Skip to content
This repository

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

Closed
adamjernst opened this Issue · 4 comments

4 participants

Adam Ernst Mattt Thompson Daniel Morgan honus
Adam Ernst

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 Thompson
Owner

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.

Oliver Jones orj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Mark Lussier intabulas referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Daniel Morgan

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!

Daniel Morgan

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

EG

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

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

        failureBlock(error);

    }];
DJ Edmonson dedmons referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
honus

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.

Evan Grim egrim referenced this issue from a commit in egrim/AFNetworking
Mattt Thompson mattt [Issue #16] Formalizing AFNetworkingErrorDomain, and constructing err…
…ors accordingly
1b52078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.