diff options
author | Vitaly Takmazov | 2020-02-03 23:34:15 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2020-02-03 23:34:15 +0300 |
commit | a097b71ab3a6aaedaef4a203d6d9804797537ed9 (patch) | |
tree | bb078f7262cba267f4228a1476c18c4f2d2250d9 /Juick | |
parent | d51c3240bd2ad236e2b72af5f4d9949ba6fe64a7 (diff) |
Display NSURLSession error
Diffstat (limited to 'Juick')
-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:^{ |