AFNetworking 2 - get error json body [duplicate]

微笑、不失礼 提交于 2019-12-14 03:53:33

问题


I'm using latest AFNetworking for my app which speaks with REST API server.

When I get some 500 error from it with JSON body something like

{ "message": "my error message" },

I cannot retrieve this message from NSError which lib responds to me:

[api setupUser:data success:^(AFHTTPRequestOperation *operation, id responseObject) {
   // some success handle
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
   // cannot get json response of error :(
}];

How do you workaround it?


回答1:


The answer was simple - operation.responseObject in failure callback contains json data as well. Sweet ^.^



来源:https://stackoverflow.com/questions/23631507/afnetworking-2-get-error-json-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!