RestKit: Getting HTTP status code when a request fails

前端 未结 3 1020
名媛妹妹
名媛妹妹 2021-02-04 04:57

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:d

相关标签:
3条回答
  • 2021-02-04 05:28

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

    operation.HTTPRequestOperation.response.statusCode

    0 讨论(0)
  • 2021-02-04 05:32

    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.

    0 讨论(0)
  • 2021-02-04 05:35

    The statusCode property found on RKResponse works for me:

    - (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error 
    {
        switch ([[objectLoader response] statusCode]) {
            case 409:
        ...
    
    }
    
    0 讨论(0)
提交回复
热议问题