Skip to content

Commit a22cac2

Browse files
committed
Proper error handling for error response in authentication
1 parent dbcd902 commit a22cac2

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

ios/OAuthManager/OAuth1Client.m

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ - (void) authorizeWithUrl:(NSString *)providerName
3131

3232
__weak id client = self;
3333
[account authenticateWithHandler:^(NSArray *responses, NSError *error) {
34-
[client clearPendingAccount];
35-
3634
if (error != nil) {
37-
onError(error);
35+
NSString *response = ((DCTAuthResponse *)responses[0]).responseDescription;
36+
NSError *err = [NSError errorWithDomain:error.domain
37+
code:error.code
38+
userInfo:@{@"response": response}];
39+
onError(err);
3840
return;
3941
}
4042

43+
[client clearPendingAccount];
44+
4145
if (!account.authorized) {
4246
NSError *err = QUICK_ERROR(E_ACCOUNT_NOT_AUTHORIZED, @"account not authorized");
4347
onError(err);

ios/OAuthManager/OAuth2Client.m

+11-4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ - (void) authorizeWithUrl:(NSString *)providerName
3434
// authorizeWithClientID
3535
[account authenticateWithHandler:^(NSArray *responses, NSError *error) {
3636
NSLog(@"authenticateWithHandler: %@", responses);
37-
[client clearPendingAccount];
3837

3938
if (error != nil) {
40-
NSLog(@"Some error: %@", error);
41-
onError(error);
39+
NSString *response = ((DCTAuthResponse *)responses[0]).responseDescription;
40+
NSError *err = [NSError errorWithDomain:error.domain
41+
code:error.code
42+
userInfo:@{@"response": response}];
43+
onError(err);
4244
return;
4345
}
46+
47+
[client clearPendingAccount];
4448

4549
if (!account.authorized) {
4650
NSError *err = QUICK_ERROR(E_ACCOUNT_NOT_AUTHORIZED, @"account not authorized");
@@ -63,7 +67,10 @@ - (void) reauthenticateWithHandler:(NSString *) providerName
6367
[account reauthenticateWithHandler:^(DCTAuthResponse *response, NSError *error) {
6468
NSLog(@"Reauthenticating...");
6569
if (error != nil) {
66-
onError(error);
70+
NSError *err = [NSError errorWithDomain:error.domain
71+
code:error.code
72+
userInfo:@{@"response": response.responseDescription}];
73+
onError(err);
6774
return;
6875
}
6976

ios/OAuthManager/OAuthManager.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,12 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
360360
} onError:^(NSError *error) {
361361
NSLog(@"Error in authorizeWithUrl: %@", error);
362362
_pendingAuthentication = NO;
363-
[manager removePending:client];
364363
callback(@[@{
365364
@"status": @"error",
366-
@"msg": [error localizedDescription]
365+
@"msg": [error localizedDescription],
366+
@"userInfo": error.userInfo
367367
}]);
368+
[manager removePending:client];
368369
}];
369370
}
370371

0 commit comments

Comments
 (0)