Define errorMessage as an informal protocol for returning error message representations rather than the description method. Document RKErrorMessage.

This commit is contained in:
Blake Watters
2012-09-20 08:04:12 -04:00
parent 3876263039
commit 04abcb8369
3 changed files with 25 additions and 9 deletions

View File

@@ -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");
}