diff --git a/Pod/Classes/AXCGiphy.m b/Pod/Classes/AXCGiphy.m index 006a4c2..8c27668 100644 --- a/Pod/Classes/AXCGiphy.m +++ b/Pod/Classes/AXCGiphy.m @@ -144,6 +144,7 @@ + (NSURLSessionDataTask *) searchGiphyWithTerm:(NSString *) searchTerm limit:(NS // json serialize error NSError * error; NSDictionary * results = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; + error = error ?: [self customErrorFromResults:results]; if (error) { block(nil, error); } else { @@ -168,6 +169,7 @@ + (NSURLSessionDataTask *) trendingGIFsWithlimit:(NSUInteger) limit offset:(NSIn // json serialize error NSError * error; NSDictionary * results = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; + error = error ?: [self customErrorFromResults:results]; if (error) { block(nil, error); } else { @@ -192,6 +194,7 @@ + (NSURLSessionDataTask *) giphyTranslationForTerm:(NSString *)term completion:( // json serialize error NSError * error; NSDictionary * results = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; + error = error ?: [self customErrorFromResults:results]; if (error) { block(nil, error); } else { @@ -217,6 +220,7 @@ + (NSURLSessionDataTask *) gifForID:(NSString *)ID completion:(void (^)(AXCGiphy // json serialize error NSError * error; NSDictionary * results = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; + error = error ?: [self customErrorFromResults:results]; if (error) { block(nil, error); } else { @@ -241,6 +245,7 @@ + (NSURLSessionDataTask *) gifsForIDs:(NSArray *)IDs completion:(void (^)(NSArra // json serialize error NSError * error; NSDictionary * results = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; + error = error ?: [self customErrorFromResults:results]; if (error) { block(nil, error); } else { @@ -252,4 +257,15 @@ + (NSURLSessionDataTask *) gifsForIDs:(NSArray *)IDs completion:(void (^)(NSArra [task resume]; return task; } + ++ (NSError *)customErrorFromResults:(NSDictionary *)results +{ + NSArray * resultsData = results[@"data"]; + if ([resultsData count] == 0) { + return [[NSError alloc] initWithDomain:@"com.giphy.ios" code:-1 userInfo:@{@"error_message" : @"No results were found"}]; + } + return nil; +} + + @end