Skip to content

Commit

Permalink
Merge pull request #2 from tsheaff/master
Browse files Browse the repository at this point in the history
added custom error handling to avoid crash in initialization of AXCGiphy
  • Loading branch information
heyalexchoi committed Feb 21, 2015
2 parents 1075105 + 4854491 commit 3c46b89
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Pod/Classes/AXCGiphy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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

0 comments on commit 3c46b89

Please sign in to comment.