From a22cac2bca6b748958fb12c5a5f4b5fb5a868472 Mon Sep 17 00:00:00 2001 From: Ari Litan Date: Tue, 17 Jan 2017 20:21:50 -0800 Subject: [PATCH] Proper error handling for error response in authentication --- ios/OAuthManager/OAuth1Client.m | 10 +++++++--- ios/OAuthManager/OAuth2Client.m | 15 +++++++++++---- ios/OAuthManager/OAuthManager.m | 5 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ios/OAuthManager/OAuth1Client.m b/ios/OAuthManager/OAuth1Client.m index 97ff342..b570104 100644 --- a/ios/OAuthManager/OAuth1Client.m +++ b/ios/OAuthManager/OAuth1Client.m @@ -31,13 +31,17 @@ - (void) authorizeWithUrl:(NSString *)providerName __weak id client = self; [account authenticateWithHandler:^(NSArray *responses, NSError *error) { - [client clearPendingAccount]; - if (error != nil) { - onError(error); + NSString *response = ((DCTAuthResponse *)responses[0]).responseDescription; + NSError *err = [NSError errorWithDomain:error.domain + code:error.code + userInfo:@{@"response": response}]; + onError(err); return; } + [client clearPendingAccount]; + if (!account.authorized) { NSError *err = QUICK_ERROR(E_ACCOUNT_NOT_AUTHORIZED, @"account not authorized"); onError(err); diff --git a/ios/OAuthManager/OAuth2Client.m b/ios/OAuthManager/OAuth2Client.m index d295ec3..092a255 100644 --- a/ios/OAuthManager/OAuth2Client.m +++ b/ios/OAuthManager/OAuth2Client.m @@ -34,13 +34,17 @@ - (void) authorizeWithUrl:(NSString *)providerName // authorizeWithClientID [account authenticateWithHandler:^(NSArray *responses, NSError *error) { NSLog(@"authenticateWithHandler: %@", responses); - [client clearPendingAccount]; if (error != nil) { - NSLog(@"Some error: %@", error); - onError(error); + NSString *response = ((DCTAuthResponse *)responses[0]).responseDescription; + NSError *err = [NSError errorWithDomain:error.domain + code:error.code + userInfo:@{@"response": response}]; + onError(err); return; } + + [client clearPendingAccount]; if (!account.authorized) { NSError *err = QUICK_ERROR(E_ACCOUNT_NOT_AUTHORIZED, @"account not authorized"); @@ -63,7 +67,10 @@ - (void) reauthenticateWithHandler:(NSString *) providerName [account reauthenticateWithHandler:^(DCTAuthResponse *response, NSError *error) { NSLog(@"Reauthenticating..."); if (error != nil) { - onError(error); + NSError *err = [NSError errorWithDomain:error.domain + code:error.code + userInfo:@{@"response": response.responseDescription}]; + onError(err); return; } diff --git a/ios/OAuthManager/OAuthManager.m b/ios/OAuthManager/OAuthManager.m index fd77ceb..df424fe 100644 --- a/ios/OAuthManager/OAuthManager.m +++ b/ios/OAuthManager/OAuthManager.m @@ -360,11 +360,12 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name } onError:^(NSError *error) { NSLog(@"Error in authorizeWithUrl: %@", error); _pendingAuthentication = NO; - [manager removePending:client]; callback(@[@{ @"status": @"error", - @"msg": [error localizedDescription] + @"msg": [error localizedDescription], + @"userInfo": error.userInfo }]); + [manager removePending:client]; }]; }