I am trying map error response from server xml. In version 0.21 of restkit it worked ok. In last version it did not (0.22 and above). Possible response from server is <authorization-fail/>
. Many server functions can lead to this response.
+ (void)addAuthErrorMapping:(RKObjectManager*)objectManager
{
RKObjectMapping* errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil
toKeyPath:@"errorMessage"]];
RKResponseDescriptor* errorResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:@"authorization-fail"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:errorResponseDescriptor];
}
In 0.21 version I am getting dictionary with authorisation-fail
key. In last versions result is empty dictionary.
This should never have worked.
The server should be returning the response to you with a non-2xx HTTP response code, and you should be using that code to trigger your response descriptor.
As it is, you're triggering the response descriptor all the time and telling it to look for - and drill into - the authorisation-fail
. So, if that key exists but is empty you should get an RKErrorMessage
that's empty.
If you have some other response descriptor that matches the response before this one (i.e. any other with a nil path pattern and success response code) then this one will never work and that is why you're getting an empty dictionary.
So, the best option is to change the server response, and the workaround solution is to use a dynamic mapping which checks the content and provides either a good response or an error mapping to be used.