NSErrorDomain name/codes for data request made through NSURLSession

I was going through the documentation of dataTaskWithRequest:completionHandler: method of NSURLSession

https://developer.apple.com/documentation/foundation/nsurlsession/1407613-datataskwithrequest

The completion handler has the third param as NSError. But I could not find the domain name for these errors. Is it expected to be NSURLErrorDomain if the error is related to the network request? Or is it kCFErrorDomainCFNetwork. Is there any exhaustive list of error domain names that one can encounter for the above method? Thanks!

  • I am seeing that kCFErrorDomainCFNetwork has nearly all the error codes that are in NSURLErrorDomain. So I think I should be using error codes from kCFErrorDomainCFNetwork. Can someone confirm? Thanks!

Add a Comment

Replies

If you’re working at the Foundation level, use the codes defined in <Foundation/NSURLError.h>. In most cases these line up with the CFNetwork code, but there’s no point using CFNetwork stuff if you can avoid it.

Is there any exhaustive list of error

You should never consider our error domains, or codes within those domains, to be exhaustive. We reserve the right to return errors in different domains and with undocumented codes.

Well-behaved errors include meaningful values in their localizedDescription property.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"