Permalink
Browse files

Merge pull request #15 from adamjernst/master

Only check HTTP status code if network error did not occur
  • Loading branch information...
Mattt Thompson
Mattt Thompson committed Aug 25, 2011
2 parents 450ff56 + ea156ec commit a129302be5d119d3d7d2acfba66407faa27f64aa
Showing with 10 additions and 8 deletions.
  1. +10 −8 AFNetworking/AFJSONRequestOperation.m
@@ -64,14 +64,16 @@ + (id)operationWithRequest:(NSURLRequest *)urlRequest
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
return [self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) {
- BOOL statusCodeAcceptable = [acceptableStatusCodes containsIndex:[response statusCode]];
- BOOL contentTypeAcceptable = [acceptableContentTypes containsObject:[response MIMEType]];
- if (!statusCodeAcceptable || !contentTypeAcceptable) {
- NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
- [userInfo setValue:[NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]] forKey:NSLocalizedDescriptionKey];
- [userInfo setValue:[request URL] forKey:NSURLErrorFailingURLErrorKey];
-
- error = [[[NSError alloc] initWithDomain:NSURLErrorDomain code:[response statusCode] userInfo:userInfo] autorelease];
+ if (!error) {
+ BOOL statusCodeAcceptable = [acceptableStatusCodes containsIndex:[response statusCode]];
+ BOOL contentTypeAcceptable = [acceptableContentTypes containsObject:[response MIMEType]];
+ if (!statusCodeAcceptable || !contentTypeAcceptable) {
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
+ [userInfo setValue:[NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]] forKey:NSLocalizedDescriptionKey];
+ [userInfo setValue:[request URL] forKey:NSURLErrorFailingURLErrorKey];
+
+ error = [[[NSError alloc] initWithDomain:NSURLErrorDomain code:[response statusCode] userInfo:userInfo] autorelease];
+ }
}
if (error) {

0 comments on commit a129302

Please sign in to comment.