If the server is capable of returning proper error messages in response, we will be able to map them and output directly to the user. So, if the server is capable of returning error message in the JSON response as follows:
{ "error": "No matching database associated with this account", "code": 1005 }
Then, we can use it to show to the user. To do so, create an error mapping for the
RKErrorMessage
class as follows:
// You can map errors to any class // RKErrorMessage is included within RestKit RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]]; // Map error information to the errorMessage property in our class [errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]]; // Anything in 4xx (Client errors) NSIndexSet *clientErrorStatusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError); // Anything in 5xx (Server errors) NSIndexSet *serverStatusCodes = RKStatusCodeIndexSetForClass...