Steve Moser
Steve Moser

Reputation: 7797

What are all the NSURLErrorDomain errors with equivalent HTTP status codes?

In the documentation for NSURLErrorDomain errors the description for NSURLErrorBadServerResponse is listed as:

Returned when the URL Loading system receives bad data from the server.

This is equivalent to the “500 Server Error” message sent by HTTP servers.

Are there other NSURLErrorDomain errors with equivalent HTTP status codes? For example, is NSURLErrorTimedOut equivalent to 408 Request Timeout?

Upvotes: 4

Views: 14443

Answers (2)

igraczech
igraczech

Reputation: 2447

Those values are defined in NSURLError.h. If you type NSURLErrorDomain into Spotlight searchon your Mac, it will find respective file somewhere, in my case inside /Library/Developer/CommandLineTools/SDKs/...

Updated URL for the URL Loading System Error Codes on Apple's Developer Site: https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes?language=occ

Upvotes: 3

zaph
zaph

Reputation: 112857

(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/)

To get the http status code cast the returned NSURLResponse to NSHTTPURLResponse and the statusCode property will have it.

Ex:

let httpResponse = response as? NSHTTPURLResponse
let statusCode = httpResponse.statusCode

For Apple's documentation go to Foundation Constants Reference and enter the error name in the upper-right search field. Also you can select the language and under Options you can select the "Deployment Target", and "Auto-expand all symbols", check "Auto-expand all symbols". enter image description here

For NSURLErrorBadServerResponse click "On This Page" and enter NSURLErrorBadServerResponse. Then click on the yellow highlighted name un der the search field. enter image description here You will be at the section: These values are returned as the error code property of an NSError object with the domain “NSURLErrorDomain”.
Scroll down (of use Safari search) to NSURLErrorBadServerResponse

NSURLErrorBadServerResponse
Returned when the URL Loading system receives bad data from the server.

This is equivalent to the “500 Server Error” message sent by HTTP servers.

Available in OS X v10.2 and later.

Other error sites that may br useful:

HTTP status codes
Status Code Definitions

Upvotes: 1

Related Questions