Reputation: 7797
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
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
Reputation: 112857
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".
For NSURLErrorBadServerResponse
click "On This Page" and enter NSURLErrorBadServerResponse. Then click on the yellow highlighted name un der the search field.
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