summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-02-03 23:34:15 +0300
committerGravatar Vitaly Takmazov2020-02-03 23:34:15 +0300
commita097b71ab3a6aaedaef4a203d6d9804797537ed9 (patch)
treebb078f7262cba267f4228a1476c18c4f2d2250d9 /Juick
parentd51c3240bd2ad236e2b72af5f4d9949ba6fe64a7 (diff)
Display NSURLSession error
Diffstat (limited to 'Juick')
-rw-r--r--Juick/APIClient.m24
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:^{