diff options
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r-- | Juick/APIClient.m | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 52b75ca..28c64ca 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -199,18 +199,24 @@ } NSURLSessionDataTask *task = [self.urlSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode; - if (!response || statusCode != 200) { - NSError *err = [NSError errorWithDomain:@"JuickErrorDomain" - code:statusCode - userInfo:nil]; + if (error) { [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - callback(nil, err); + callback(nil, error); }]; } else { - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - callback(data, error); - }]; + NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode; + if (!response || statusCode != 200) { + NSError *err = [NSError errorWithDomain:@"JuickErrorDomain" + code:statusCode + userInfo:nil]; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil, err); + }]; + } else { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(data, error); + }]; + } } }]; [self.backgroundQueue addOperationWithBlock:^{ |