RestKit: Getting HTTP status code when a request fails

pepsi picture pepsi · Nov 21, 2011 · Viewed 8k times · Source

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

Answer

Kevin R picture Kevin R · Apr 2, 2013

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

operation.HTTPRequestOperation.response.statusCode