mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 20:31:13 +08:00
Define errorMessage as an informal protocol for returning error message representations rather than the description method. Document RKErrorMessage.
This commit is contained in:
@@ -33,16 +33,19 @@
|
||||
/**
|
||||
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:@"description"` against the array, and joining the descriptions by comma to form a single string value. This error construction
|
||||
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 `errorMessage` property is significant as it is an informal protocol that must be adopted by objects wishing to representing response errors.
|
||||
|
||||
@return An error object representing the objects contained in the mapping result.
|
||||
@see `RKErrorMessage`
|
||||
*/
|
||||
static NSError *RKErrorFromMappingResult(RKMappingResult *mappingResult)
|
||||
{
|
||||
NSArray *collection = [mappingResult array];
|
||||
NSString *description = nil;
|
||||
if ([collection count] > 0) {
|
||||
description = [[collection valueForKeyPath:@"description"] componentsJoinedByString:@", "];
|
||||
description = [[collection valueForKeyPath:@"errorMessage"] componentsJoinedByString:@", "];
|
||||
} else {
|
||||
RKLogWarning(@"Expected mapping result to contain at least one object to construct an error");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user