Reputation: 509
I'm using
NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:@"paths/" parameters:params];
AFJSONRequestOperation *jsonRequest = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request success:^(NSURLRequest *request,
NSHTTPURLResponse *response, id JSON) {
// something to do here in case of success
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON
{
// and something there in case of failure
}
Everything works fine, except in one case, when I receive a response with 400 status code, and a JSON
(valid, I've checked) containing some information about this error, as I can see using the browser.
But JSONRequestOperationWithRequest
calls success block, and JSON
and response are nil.
What could cause this?
Upvotes: 1
Views: 1786
Reputation: 19544
Failure is called if the requestOperation has an associated error after finishing. Reasons for an error include the response having the incorrect Content-Type, not having an acceptable status code (2XX range, by default, but this can be changed with AFHTTPRequestOperation +addAcceptableStatusCodes:
), or an error processing the downloaded data. This is guaranteed behavior.
You may get JSON objects in a 400 response as part of the failure
block, and you may get a nil
JSON in the success
. These are both consistent with how AFNetworking works.
Upvotes: 5