Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Don't create NSErrors with NSURLErrorDomain and bogus error codes #16

adamjernst opened this Issue Aug 24, 2011 · 4 comments


None yet
4 participants

adamjernst commented Aug 24, 2011

This code (in AFJSONRequestOperation.m) is incorrect:

error = [[[NSError alloc] initWithDomain:NSURLErrorDomain code:[response statusCode] userInfo:userInfo] autorelease];

We should not be creating errors with system domains (or at the very least, we shouldn't be assigning the HTTP status code as the error's code, since there are actual NSURLError error codes that handling code might expect).

One possible fix is to create AFNetworkingHTTPErrorDomain and document (in that declaration) that the codes for that domain are equivalent to HTTP status codes.

mattt added a commit that referenced this issue Sep 15, 2011


mattt commented Sep 15, 2011

Finally got around to correcting this with d62af91. AFNetworkingErrorDomain is declared, and its error codes corresponds to those in NSURLErrorDomain. I went through and got everything behaving correctly for error serving / handling. The nudge to Do The Right Thing™ here is much appreciated.

@mattt mattt closed this Sep 15, 2011

morgz commented Oct 28, 2011

I'm finding this a little annoying.. For example in my rails app I pass down a status code.. I want to react to this in my app. Instead I get a string which contains my http code and a AFNetworkingErrorDomain code which represents, for example a 401 (unauthorised) as -1011

Maybe that's just me but I want to set the codes!

morgz commented Oct 28, 2011

OK spoke to soon. If anyone else comes across this, the lovely Gowalla's have put it in the NSHTTPURLResponse *response.


failure:^(NSHTTPURLResponse *response, NSError *error) {

        NSLog(@"Response Code: %d",[response statusCode]);



honus commented Sep 9, 2012

I'm not a big fan of using your own domain with codes that are the same as ones in the NSURLErrorDomain. It makes it very hard to guess what error codes you might get. I think you'd be better off explicitly defining the error codes you are going to use. I don't see what you get out of using the same value for the codes other than not having to define a few constants.

If what you are really doing is passing along the code from an NSError that had something in the NSURLErrorDomain then create a code in the AFNetworkingErrorDomain that indicates it is wrapping another error and include that NSError in the user dictionary.

egrim pushed a commit to egrim/AFNetworking that referenced this issue Sep 18, 2012

timd pushed a commit to timd/AFNetworking that referenced this issue Dec 3, 2012

Merge pull request #16 from johnezang/master
Source tidies.  There should be zero changes in functionality.

greghe pushed a commit to skillz/AFNetworking that referenced this issue Sep 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment