0

I am using Restkit .20 and trying to get the error object returned in a failure block. I have tried both below and both return (null) for the error object.

RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
[errorMapping addPropertyMapping:
 [RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];
RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
                                                                                pathPattern:nil
                                                                                    keyPath:@"error" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];
[self.objectManager addResponseDescriptorsFromArray:@[errorDescriptor]];

AND

RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"error" toKeyPath:@"errorMessage"]];
[self.objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:errorMapping pathPattern:nil keyPath:@"error" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)]];

This is in my failure block which prints out "errorMessage: (null)"

 failure:^(RKObjectRequestOperation *operation, NSError *error) 
{
        NSLog(@"errorMessage: %@", [[error userInfo] objectForKey:RKObjectMapperErrorObjectsKey]);
}

Here is what is return from in the JSON from the server.

{
    "status": "FAIL",
    "user_errors": null,
    "error": "Credit card type is not accepted by this merchant account.",
    "user": null
}
4

1 に答える 1