[Issue #1221] Refactoring lock for HTTP error
This commit is contained in:
parent
7562fce4b9
commit
2b8acb7c3f
1 changed files with 4 additions and 20 deletions
|
|
@ -108,10 +108,10 @@ static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
@interface AFHTTPRequestOperation ()
|
@interface AFHTTPRequestOperation ()
|
||||||
@property (readwrite, nonatomic, strong) NSRecursiveLock *lock;
|
|
||||||
@property (readwrite, nonatomic, strong) NSURLRequest *request;
|
@property (readwrite, nonatomic, strong) NSURLRequest *request;
|
||||||
@property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;
|
@property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;
|
||||||
@property (readwrite, strong) NSError *HTTPError;
|
@property (readwrite, nonatomic, strong) NSError *HTTPError;
|
||||||
|
@property (readwrite, nonatomic, strong) NSRecursiveLock *lock;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AFHTTPRequestOperation
|
@implementation AFHTTPRequestOperation
|
||||||
|
|
@ -122,24 +122,6 @@ static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL
|
||||||
@dynamic request;
|
@dynamic request;
|
||||||
@dynamic response;
|
@dynamic response;
|
||||||
|
|
||||||
- (NSError *)HTTPError
|
|
||||||
{
|
|
||||||
[self.lock lock];
|
|
||||||
NSError *HTTPError = _HTTPError;
|
|
||||||
[self.lock unlock];
|
|
||||||
|
|
||||||
return HTTPError;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setHTTPError:(NSError *)HTTPError
|
|
||||||
{
|
|
||||||
[self.lock lock];
|
|
||||||
if (HTTPError != _HTTPError) {
|
|
||||||
_HTTPError = HTTPError;
|
|
||||||
}
|
|
||||||
[self.lock unlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
if (_successCallbackQueue) {
|
if (_successCallbackQueue) {
|
||||||
#if !OS_OBJECT_USE_OBJC
|
#if !OS_OBJECT_USE_OBJC
|
||||||
|
|
@ -157,6 +139,7 @@ static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSError *)error {
|
- (NSError *)error {
|
||||||
|
[self.lock lock];
|
||||||
if (!self.HTTPError && self.response) {
|
if (!self.HTTPError && self.response) {
|
||||||
if (![self hasAcceptableStatusCode] || ![self hasAcceptableContentType]) {
|
if (![self hasAcceptableStatusCode] || ![self hasAcceptableContentType]) {
|
||||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||||
|
|
@ -178,6 +161,7 @@ static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[self.lock unlock];
|
||||||
|
|
||||||
if (self.HTTPError) {
|
if (self.HTTPError) {
|
||||||
return self.HTTPError;
|
return self.HTTPError;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue