Swift Combine in UIKit. URLSession dataTaskPublisher NSURLErrorDomain -1 for some users

is this error coming from (speaking in olde terms of URLSession API) error closure parameter or response? it looks it's coming from the latter, but worth to double check.

in the above code around the lines where you check for 200, change that code so it thinks it's getting 499.

it's good idea (at least in debug builds) to show exact error from URLResponses (and treat those different in logs to OS errors). something like this:

URLSession.dataTask(...) { data, response, error in
    if let err = error {
        logOrShowError("OS level Error", err.localizedDescription) // or debugDescription
    } else if let err = response.httpError {
        logOrShowError("URLResponse level Error", err.localizedDescription) // or debugDescription
    } else {
        parse data
        if let err = parsing error {
            logOrShowError("Parsing Data Error", err.localizedDescription) // or debugDescription
        }
        if let err = parsedObject.err { // errors could be at this level as well, depending upon a particular API
            logOrShowError("Data level Error", err.localizedDescription) // or debugDescription
        ...
    }
}

where response.httpError is an extension that parses httpStatus out of response and converts it into an error. (i'd also use "reason phrase" for further details about the error but unfortunately it's not available in URLSession API, i never understood why :frowning_face:)