Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestKit: Getting HTTP status code when a request fails

I'm using RestKit in an iOS app and I need to have special handling for certain HTTP error codes. How can the the response HTTP status code be checked inside of request:didFailLoadWithError:? Is there some entry in the userInfo dictionary of the NSError?

I couldn't find anything in the RKRequestDelegate documentation.

Here's the interface for the delegate method:

- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error
like image 802
pepsi Avatar asked Nov 21 '11 21:11

pepsi


People also ask

What is the HTTP status code for bad request?

The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).

What is HTTP status code1?

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.


3 Answers

For people using the new version of RESTkit and objectManager, you can fetch the statuscode from the RKObjectRequestOperation:

operation.HTTPRequestOperation.response.statusCode

like image 148
Kevin R Avatar answered Oct 20 '22 03:10

Kevin R


It turns out that didFailLoadWithError: is not called for HTTP errors. The request:didLoadResponse: method is still called for HTTP errors, so the response (and hence the status codes) are available.

like image 44
pepsi Avatar answered Oct 20 '22 05:10

pepsi


The statusCode property found on RKResponse works for me:

- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error 
{
    switch ([[objectLoader response] statusCode]) {
        case 409:
    ...

}
like image 30
mja Avatar answered Oct 20 '22 03:10

mja