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

Commit 9af954c

Browse files
committed
Better error handling in Facebook providers.
1 parent 04e99aa commit 9af954c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Providers/Facebook/SimpleAuthFacebookProvider.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,22 @@ - (RACSignal *)remoteAccountWithSystemAccount:(ACAccount *)account {
8383
[subscriber sendCompleted];
8484
}
8585
else {
86-
[subscriber sendError:parseError];
86+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
87+
if (parseError) {
88+
dictionary[NSUnderlyingErrorKey] = parseError;
89+
}
90+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary];
91+
[subscriber sendNext:error];
8792
}
8893
}
8994
else {
90-
[subscriber sendError:connectionError];
95+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
96+
if (connectionError) {
97+
dictionary[NSUnderlyingErrorKey] = connectionError;
98+
}
99+
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
100+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
101+
[subscriber sendError:error];
91102
}
92103
}];
93104
return nil;

Providers/FacebookWeb/SimpleAuthFaceBookWebProvider.m

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken {
107107
[CMDQueryStringSerialization queryStringWithDictionary:parameters]];
108108
NSURL *URL = [NSURL URLWithString:URLString];
109109
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
110-
[NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue
111-
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
110+
[NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
112111
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 99)];
113112
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
114113
if ([indexSet containsIndex:statusCode] && data) {
@@ -119,11 +118,22 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken {
119118
[subscriber sendCompleted];
120119
}
121120
else {
122-
[subscriber sendError:parseError];
121+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
122+
if (parseError) {
123+
dictionary[NSUnderlyingErrorKey] = parseError;
124+
}
125+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary];
126+
[subscriber sendNext:error];
123127
}
124128
}
125129
else {
126-
[subscriber sendError:connectionError];
130+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
131+
if (connectionError) {
132+
dictionary[NSUnderlyingErrorKey] = connectionError;
133+
}
134+
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
135+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
136+
[subscriber sendError:error];
127137
}
128138
}];
129139
return nil;

0 commit comments

Comments
 (0)