mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-11 02:01:29 +08:00
Update RKObjectMapper to return a single NSError on failure. Update error codes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
// Factored into a method to support RKManagedObjectLoader
|
||||
- (RKMappingResult *)performMappingWithMapper:(RKObjectMapper *)mapper
|
||||
{
|
||||
return [mapper performMapping];
|
||||
return [mapper performMapping:nil];
|
||||
}
|
||||
|
||||
- (RKMapping *)configuredObjectMapping
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user