summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-03-22 15:25:10 +0300
committerGravatar Vitaly Takmazov2019-03-22 15:25:10 +0300
commit387eca3bd36e3fd27e3dfb96f7a280f489e0a022 (patch)
tree1ea5b0bfbc9eb2a3985e48407a73869058f9bd99
parenta3273df2e699c7332bd9ec95a382ec0ba1de3be4 (diff)
Handle non-200 status codes
-rw-r--r--Juick/APIClient.m19
1 files changed, 12 insertions, 7 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index e2ef67d..ac827e0 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -56,13 +56,18 @@
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.backgroundQueue addOperationWithBlock:^{
[self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSMutableArray *messages = [NSMutableArray new];
- [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [messages addObject:[Message fromJSON:obj]];
- }];
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- callback(messages, nil);
- }];
+ NSInteger statusCode = [((NSHTTPURLResponse *) task.response) statusCode];
+ if (statusCode == 200) {
+ NSMutableArray *messages = [NSMutableArray new];
+ [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+ [messages addObject:[Message fromJSON:obj]];
+ }];
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ callback(messages, nil);
+ }];
+ } else {
+ callback(nil, [NSError errorWithDomain:@"JuickErrorDomain" code:statusCode userInfo:nil]);
+ }
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"REST Error: %@", error);