NSError from HTTP status code
What is the best way to create an object NSError
based on a standard HTTP status code (ideally one that contains some kind of human-readable message in localizedDescription
)? Is there a standard method or should I just create my own error domain to use with NSError
?
Foundation objects for making network requests will often return these NSError
for you. NSURLConnection
for example will provide NSError
in completionHandler
its method +sendAsynchronousRequest:queue:completionHandler:
.
If you want to rollback yourself, you can instantiate it NSError
, set it as error domain like NSURLErrorDomain
, set it code
as the HTTP status code you want, and set it localizedDescription
to be user-readable.