Update RKObjectMapper to return a single NSError on failure. Update error codes

This commit is contained in:
Blake Watters
2012-08-17 13:09:47 -04:00
parent ea8a920309
commit e7d768dd2f
8 changed files with 20 additions and 5 deletions

View File

@@ -28,3 +28,5 @@ enum {
RKMappingErrorFromMappingResult = 1004, // The error was returned from the mapping result
RKMappingErrorValidationFailure = 1005 // Generic error code for use when constructing validation errors
};
extern NSString * const RKMappingErrorKeyPathErrorKey; // The key path the error is associated with

View File

@@ -255,7 +255,7 @@
// Factored into a method to support RKManagedObjectLoader
- (RKMappingResult *)performMappingWithMapper:(RKObjectMapper *)mapper
{
return [mapper performMapping];
return [mapper performMapping:nil];
}
- (RKMapping *)configuredObjectMapping

View File

@@ -45,6 +45,7 @@
// Primary entry point for the mapper. Examines the type of object and processes it appropriately...
- (RKMappingResult *)performMapping;
- (RKMappingResult *)performMapping:(NSError **)error;
@end

View File

@@ -23,6 +23,9 @@
#import "RKObjectMappingProvider+Contexts.h"
#import "RKObjectMappingOperationDataSource.h"
#import "RKMappingErrors.h"
#import "RKMappingDescriptor.h"
NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
// Set Logging Component
#undef RKLogComponent
@@ -334,7 +337,7 @@
}
// Primary entry point for the mapper.
- (RKMappingResult *)performMapping
- (RKMappingResult *)performMapping:(NSError **)error
{
NSAssert(self.sourceObject != nil, @"Cannot perform object mapping without a source object to map from");
NSAssert(self.mappingProvider != nil, @"Cannot perform object mapping without an object mapping provider");
@@ -377,7 +380,13 @@
// If the content is empty, we don't consider it an error
BOOL isEmpty = [self.sourceObject respondsToSelector:@selector(count)] && ([self.sourceObject count] == 0);
if (foundMappable == NO && !isEmpty) {
[self addErrorForUnmappableKeyPath:@""];
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"Unable to find any mappings for the given content", nil), NSLocalizedDescriptionKey,
[NSNull null], RKMappingErrorKeyPathErrorKey,
self.errors, RKDetailedErrorsKey,
nil];
NSError *compositeError = [[NSError alloc] initWithDomain:RKErrorDomain code:RKMappingErrorNotFound userInfo:userInfo];
if (error) *error = compositeError;
return nil;
}