Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSError from HTTP status code

What's the best way to create an NSError object based on a standard HTTP status code (ideally one which includes some human-readable message in the localizedDescription)? Is there a standard method or should I just create my own error domain to use with NSError?

like image 869
devios1 Avatar asked Aug 05 '26 13:08

devios1


1 Answers

Foundation's objects for performing network requests will often return these NSErrors for you. NSURLConnection, for example, will provide an NSError in the completionHandler of its +sendAsynchronousRequest:queue:completionHandler: method.

If you'd like to roll your own you could create an instance of an NSError, set its error domain to be NSURLErrorDomain, set its code to be the HTTP status code you want, and set its localizedDescription to be the human readable string you need.

like image 71
Tim Johnsen Avatar answered Aug 08 '26 01:08

Tim Johnsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!