mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-14 23:28:07 +08:00
Relax the use of use an the informal procotol for the errorMessage property in favor of the description method. closes #1104, closes #1087, closes #1095
* Change contract to the use the `description` method instead of `errorMessage`. This makes it work with any class out of the box * Add import for RKErrorMessage to the Support.h header so it is immediately available * Fix incorrect keyPath in the README.md * Add additional notes about how the errors are constructed to the README
This commit is contained in:
@@ -197,9 +197,9 @@
|
||||
/**
|
||||
Returns a representation of a mapping result as an `NSError` value.
|
||||
|
||||
The returned `NSError` object is in the `RKErrorDomain` domain and has the `RKMappingErrorFromMappingResult` code. The value for the `NSLocalizedDescriptionKey` is computed by retrieving the objects in the mapping result as an array, evaluating `valueForKeyPath:@"errorMessage"` against the array, and joining the returned error messages by comma to form a single string value. The source error objects are returned with the `NSError` in the `userInfo` dictionary under the `RKObjectMapperErrorObjectsKey` key.
|
||||
The returned `NSError` object is in the `RKErrorDomain` domain and has the `RKMappingErrorFromMappingResult` code. The value for the `NSLocalizedDescriptionKey` is computed by retrieving the objects in the mapping result as an array, evaluating `valueForKeyPath:@"description"` against the array, and joining the returned error messages by comma to form a single string value. The source error objects are returned with the `NSError` in the `userInfo` dictionary under the `RKObjectMapperErrorObjectsKey` key.
|
||||
|
||||
The `errorMessage` property is significant as it is an informal protocol that must be adopted by objects wishing to representing response errors.
|
||||
This implementation assumes that the class used to represent the response error will return a string description of the client side error when sent the `description` message.
|
||||
|
||||
@return An error object representing the objects contained in the mapping result.
|
||||
@see `RKErrorMessage`
|
||||
|
||||
@@ -37,7 +37,7 @@ NSError *RKErrorFromMappingResult(RKMappingResult *mappingResult)
|
||||
NSArray *collection = [mappingResult array];
|
||||
NSString *description = nil;
|
||||
if ([collection count] > 0) {
|
||||
description = [[collection valueForKeyPath:@"errorMessage"] componentsJoinedByString:@", "];
|
||||
description = [[collection valueForKeyPath:@"description"] componentsJoinedByString:@", "];
|
||||
} else {
|
||||
RKLogWarning(@"Expected mapping result to contain at least one object to construct an error");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user