The errorMapping is defined as:
[[[[RKObjectManager sharedManager] mappingProvider] errorMapping] setRootKeyPath:@"error"];
It works well with simple error message as a string:
render status: :unprocessable_entity, json: { :error => 'cannot create topic' }
However, fails with hash response:
render status: :unprocessable_entity, json: { :error => @topic.errors }
and gives:
W
restkit.object_mapping:RKObjectMappingOperation.m:239:-[RKObjectMappingOperation
transformValue:atKeyPath:toType:] Failed transformation of value at
keyPath ”. No strategy for transforming from ‘JKDictionary’ to
‘NSString’
Is there is way to configure RestKit errorMapping to accept hash response (and hopefully stores in NSDictionary)?
I assume you are using the default error mapping? This maps an error keypath to a RKErrorMessage class. This class expects an NSString, but you have a NSDictionary (JKDictionary because you are using by JSONKit, but still…).
If you don’t want to modify your server code, you can create your own error class on the iPhone and replace this default mapping. For an example you can see RKErrorMessage.m and also [RKObjectManager init] where the default map is created.