Restkit json error response msg from server

后端 未结 4 757
暖寄归人
暖寄归人 2020-12-28 18:50

I have used many hours on how to solve this issue. Im using Restkit 0.9.3 with Object Mapping 2.0. All data is in JSON. I can make GET, POST, PUT and DELETE operations corre

4条回答
  •  粉色の甜心
    2020-12-28 19:18

    if an object is returned your delegate should call this method:

    - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {}
    

    in this method you should call an instance of your "error" class and map 'code' and 'message' as necessary.

    An easier way to handle errors though would be to use:

    - (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
    
    if(objectLoader.response.statusCode == 401)
    { ...
    

    And show the necessary error message in that method.

提交回复
热议问题