I have this piece of code :
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
{
if ([response respondsToSelector:@selector(statusCode)]) {
int statusCode = [((NSHTTPURLResponse*)response) statusCode];
if (statusCode >= 400) {
NSError* statusError = [NSError errorWithDomain:@"Server connection error" code:statusCode userInfo:nil];
[self connection:connection didFailWithError:statusError];
}
}
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
NSLog(@"%@", [error localizedDescription]);
}
That gives for a missing page :
--> The operation couldn’t be completed. (Server connection error error 404.)
From where does that description (localized or not) comes from ?
I've just initialized the NSError with a code and a custom meaningless domain string...
A string containing the error domain. The user info dictionary.
NSError is a Cocoa class. An NSError object encapsulates information about an error condition in an extendable, object-oriented manner. It consists of a predefined error domain, a domain-specific error code, and a user info dictionary containing application-specific information.
Each NSError object encodes three critical pieces of information: a status code , corresponding to a particular error domain , as well as additional context provided by a userInfo dictionary.
That error message means that your online resource cannot be found by the server.
For example: http://www.google.com/notthepageyourelookingfor.
HTTP 404 - Wikipedia
If you're asking where the error message originates, it ought to break down like this:
localizedDescription
:
The operation couldn't be completed ()
By default this method returns the object in the user info dictionary for the key NSLocalizedDescriptionKey. If the user info dictionary doesn’t contain a value for NSLocalizedDescriptionKey, a default string is constructed from the domain and code. NSLocalizedDescriptionKey is a localized string representation of the error that, if present, will be returned by localizedDescription. Available in Mac OS X v10.2 and later. Declared in NSError.h.
errWithDomain:@"Server connection error"
:
Server connection error
code:statusCode
:
error 404
The operation couldn’t be completed.
That is a standard POSIX error. Your domain and error code are just appended to the actual error message to determine the error's origin. Usually, a reverse-DNS style domain is used, like com.developer.package
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With