17

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
pepsi
  • 6,785
  • 6
  • 42
  • 74

3 Answers3

52

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

operation.HTTPRequestOperation.response.statusCode

Kevin R
  • 8,230
  • 4
  • 41
  • 46
3

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.

pepsi
  • 6,785
  • 6
  • 42
  • 74
1

The statusCode property found on RKResponse works for me:

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

}
mja
  • 5,056
  • 1
  • 29
  • 40
  • I'm just using the RKClient, so I get notified through the RKRequestDelegate, not the ObjectManagerDelegate. All the RKRequestDelegate provides for errors is the RKRequest and an NSError. – pepsi Nov 21 '11 at 21:37
  • RKRequest has a response property in 0.10.3. – Jon Sep 25 '13 at 12:21