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 | |
parent | d51c3240bd2ad236e2b72af5f4d9949ba6fe64a7 (diff) |
Display NSURLSession error
-rw-r--r-- | Juick.xcodeproj/project.pbxproj | 12 | ||||
-rw-r--r-- | Juick/APIClient.m | 24 |
2 files changed, 21 insertions, 15 deletions
diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 78252e3..65abdb4 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -720,7 +720,7 @@ CODE_SIGN_ENTITLEMENTS = Juick/Juick.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 135; + CURRENT_PROJECT_VERSION = 136; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = KH4MX79ZK7; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -742,7 +742,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Juick/Juick.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 135; + CURRENT_PROJECT_VERSION = 136; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Juick/Supporting Files/Juick-Prefix.pch"; @@ -770,7 +770,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 135; + CURRENT_PROJECT_VERSION = 136; DEBUG_INFORMATION_FORMAT = dwarf; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = KH4MX79ZK7; @@ -802,7 +802,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 135; + CURRENT_PROJECT_VERSION = 136; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; GCC_C_LANGUAGE_STANDARD = gnu11; @@ -883,7 +883,7 @@ CODE_SIGN_ENTITLEMENTS = Juick/Juick.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 135; + CURRENT_PROJECT_VERSION = 136; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = KH4MX79ZK7; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -912,7 +912,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 135; + CURRENT_PROJECT_VERSION = 136; DEBUG_INFORMATION_FORMAT = dwarf; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = KH4MX79ZK7; 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:^{ |