mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Reworked object loader to check if a response is mappable even if it is an error. We had an assertion failure that could be triggered by trying to load a remote error payload in a non-mappable format (i.e. text/html).
This commit is contained in:
@@ -197,17 +197,19 @@
|
||||
}
|
||||
|
||||
- (BOOL)isResponseMappable {
|
||||
if ([self.response isServiceUnavailable]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKServiceDidBecomeUnavailableNotification object:self];
|
||||
}
|
||||
|
||||
if ([self.response isFailure]) {
|
||||
[(NSObject<RKObjectLoaderDelegate>*)_delegate objectLoader:self didFailWithError:self.response.failureError];
|
||||
|
||||
[self finalizeLoad:NO];
|
||||
|
||||
return NO;
|
||||
} else if ([self.response isError]) {
|
||||
[self handleResponseError];
|
||||
return NO;
|
||||
} else if ([self.response isSuccessful] && NO == [self canParseMIMEType:[self.response MIMEType]]) {
|
||||
RKLogWarning(@"Encountered unexpected response code: %d (MIME Type: %@)", self.response.statusCode, self.response.MIMEType);
|
||||
} else if (NO == [self canParseMIMEType:[self.response MIMEType]]) {
|
||||
// We can't parse the response, it's unmappable regardless of the status code
|
||||
RKLogWarning(@"Encountered unexpected response with status code: %d (MIME Type: %@)", self.response.statusCode, self.response.MIMEType);
|
||||
if ([_delegate respondsToSelector:@selector(objectLoaderDidLoadUnexpectedResponse:)]) {
|
||||
[(NSObject<RKObjectLoaderDelegate>*)_delegate objectLoaderDidLoadUnexpectedResponse:self];
|
||||
} else {
|
||||
@@ -218,16 +220,16 @@
|
||||
[self finalizeLoad:NO];
|
||||
|
||||
return NO;
|
||||
} else if ([self.response isError]) {
|
||||
// This is an error and we can map the MIME Type of the response
|
||||
[self handleResponseError];
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)handleResponseError {
|
||||
if ([self.response isServiceUnavailable]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKServiceDidBecomeUnavailableNotification object:self];
|
||||
}
|
||||
|
||||
// Since we are mapping what we know to be an error response, we don't want to map the result back onto our
|
||||
// target object
|
||||
NSError* error = nil;
|
||||
|
||||
Reference in New Issue
Block a user