Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Better error handling in Facebook providers.
Browse files Browse the repository at this point in the history
  • Loading branch information
calebd committed Oct 2, 2014
1 parent 04e99aa commit 9af954c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 13 additions & 2 deletions Providers/Facebook/SimpleAuthFacebookProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,22 @@ - (RACSignal *)remoteAccountWithSystemAccount:(ACAccount *)account {
[subscriber sendCompleted];
}
else {
[subscriber sendError:parseError];
NSMutableDictionary *dictionary = [NSMutableDictionary new];
if (parseError) {
dictionary[NSUnderlyingErrorKey] = parseError;
}
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary];
[subscriber sendNext:error];
}
}
else {
[subscriber sendError:connectionError];
NSMutableDictionary *dictionary = [NSMutableDictionary new];
if (connectionError) {
dictionary[NSUnderlyingErrorKey] = connectionError;
}
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
[subscriber sendError:error];
}
}];
return nil;
Expand Down
18 changes: 14 additions & 4 deletions Providers/FacebookWeb/SimpleAuthFaceBookWebProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken {
[CMDQueryStringSerialization queryStringWithDictionary:parameters]];
NSURL *URL = [NSURL URLWithString:URLString];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
[NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 99)];
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
if ([indexSet containsIndex:statusCode] && data) {
Expand All @@ -119,11 +118,22 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken {
[subscriber sendCompleted];
}
else {
[subscriber sendError:parseError];
NSMutableDictionary *dictionary = [NSMutableDictionary new];
if (parseError) {
dictionary[NSUnderlyingErrorKey] = parseError;
}
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary];
[subscriber sendNext:error];
}
}
else {
[subscriber sendError:connectionError];
NSMutableDictionary *dictionary = [NSMutableDictionary new];
if (connectionError) {
dictionary[NSUnderlyingErrorKey] = connectionError;
}
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
[subscriber sendError:error];
}
}];
return nil;
Expand Down

0 comments on commit 9af954c

Please sign in to comment.