devios1
devios1

Reputation: 38035

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?

Upvotes: 3

Views: 2237

Answers (1)

Tim Johnsen
Tim Johnsen

Reputation: 1501

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.

Upvotes: 2

Related Questions