I see that there is a list of accepted http status codes that I can modify, but I think it would be cleaner if I can get the http status code in the failure block ..
Ok, found the answer with the operation object
failure:^(AFHTTPRequestOperation *operation, NSError *error){ NSLog(@"error code %d",[operation.response statusCode]); }];
To get the status code of an HTTP request made with the fetch method, access the status property on the response object. The response. status property contains the HTTP status code of the response, e.g. 200 for a successful response or 500 for a server error. Copied!
If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead.
We tend to get -1 status codes when there are network issues or connection problems, so we display the user a network problems page in those cases.
Ok, found the answer with the operation object
failure:^(AFHTTPRequestOperation *operation, NSError *error){ NSLog(@"error code %d",[operation.response statusCode]); }];
In newer versions of AFNetworking, you can retrieve the response object from the error:
[[[error userInfo] objectForKey:AFNetworkingOperationFailingURLResponseErrorKey] statusCode]
This is handy if you're doing error handling further up the line and don't want to pass around the response object.
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