Minor refactoring to AFHTTPRequestOperation
This commit is contained in:
parent
0c25bcee82
commit
eabde28fd6
1 changed files with 3 additions and 8 deletions
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
@interface AFHTTPRequestOperation ()
|
@interface AFHTTPRequestOperation ()
|
||||||
@property (readwrite, nonatomic, retain) NSError *HTTPError;
|
@property (readwrite, nonatomic, retain) NSError *HTTPError;
|
||||||
@property (readonly, nonatomic, assign) BOOL hasContent;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AFHTTPRequestOperation
|
@implementation AFHTTPRequestOperation
|
||||||
|
|
@ -62,7 +61,7 @@
|
||||||
[userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
[userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||||
|
|
||||||
self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease];
|
self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease];
|
||||||
} else if ([self hasContent] && ![self hasAcceptableContentType]) { // Don't invalidate content type if there is no content
|
} else if ([self.responseData length] > 0 && ![self hasAcceptableContentType]) { // Don't invalidate content type if there is no content
|
||||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||||
[userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), self.acceptableContentTypes, [self.response MIMEType]] forKey:NSLocalizedDescriptionKey];
|
[userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), self.acceptableContentTypes, [self.response MIMEType]] forKey:NSLocalizedDescriptionKey];
|
||||||
[userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
[userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||||
|
|
@ -71,17 +70,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_HTTPError) {
|
if (self.HTTPError) {
|
||||||
return _HTTPError;
|
return self.HTTPError;
|
||||||
} else {
|
} else {
|
||||||
return [super error];
|
return [super error];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hasContent {
|
|
||||||
return [self.responseData length] > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)hasAcceptableStatusCode {
|
- (BOOL)hasAcceptableStatusCode {
|
||||||
return !self.acceptableStatusCodes || [self.acceptableStatusCodes containsIndex:[self.response statusCode]];
|
return !self.acceptableStatusCodes || [self.acceptableStatusCodes containsIndex:[self.response statusCode]];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue