Reputation: 1666
Is there a possibility that AFNetworking
takes API
status code in consideration as well?
Call returns 200 HTTP code that it is ok, but status code is 406 which indicates failure.
This results to AFNetworking
success block being called, even though API call failed.
Is there a solution to this?
Code:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *APICallURL = [NSString stringWithFormat:@"%@/%@", SERVER_URL, @"something.php"];
[manager GET:APICallURL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success();
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(error);
}
}];
Upvotes: 0
Views: 654
Reputation: 32681
X-API-Status-Code
is a totally non-standard header (as any header starting with X-...
actually, by definition).
That header is a proprietary way that your specific server chose to report the API status code. It could have picked any other proprietary header to do so, maybe calling it X-API-ReturnCode
or whatnot.
So I doubt that AFNetworking
will ever support this natively.
But you can probably create your own AFURLResponseSerialization
subclass and implement validateResponse
, so that your code check for this proprietary header and act accordingly.
Upvotes: 2
Reputation: 46
It will not reach failure block for any failure status code from server. With respect to AFNetworking, network call is successful with a error code from server.
It will reach failure block only when we are not able to successfully finish the network call, like 1) Time out error 2) Server down and not able to reach 3) Network loss etc
Solution is we should check the status code of network call in success block and identify error responses from server
Upvotes: 1