Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESD-30932] Improve error handling #720

Merged
merged 12 commits into from
Sep 25, 2023
1 change: 1 addition & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- `customScheme` is now part of `ClearSessionOptions` instead of `ClearSessionParameters` in `clearSession`
- iOS minimum deployment target is now 13. This can be migrated by adding `platform :ios '13.0'` to the ios/Podfile file
- Additional or custom parameters to be sent in `authorize` method should now be sent as `additionalParameters`. This includes when sending `prompt` parameter.
- Error codes are now platform specific. For example - When user cancels authentication, Android error code is `a0.session.user_cancelled` and iOS error code is `USER_CANCELLED`

### Callback URL migration

Expand Down
20 changes: 14 additions & 6 deletions android/src/main/java/com/auth0/react/A0Auth0Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onSuccess(Credentials credentials) {

@Override
public void onFailure(@NonNull CredentialsManagerException e) {
promise.reject(ERROR_CODE, e.getMessage());
promise.reject(ERROR_CODE, e.getMessage(), e);
}
});
}
Expand All @@ -94,7 +94,7 @@ public void saveCredentials(ReadableMap credentials, Promise promise) {
this.secureCredentialsManager.saveCredentials(CredentialsParser.fromMap(credentials));
promise.resolve(true);
} catch (CredentialsManagerException e) {
promise.reject(ERROR_CODE, e.getMessage());
promise.reject(ERROR_CODE, e.getMessage(), e);
}
}

Expand All @@ -110,7 +110,7 @@ public void enableLocalAuthentication(String title, String description, Promise
A0Auth0Module.this.secureCredentialsManager.requireAuthentication(activity, LOCAL_AUTH_REQUEST_CODE, title, description);
promise.resolve(true);
} catch (CredentialsManagerException e){
promise.reject(ERROR_CODE, e.getMessage());
promise.reject(ERROR_CODE, e.getMessage(), e);
}
});
}
Expand Down Expand Up @@ -213,14 +213,22 @@ public void onFailure(AuthenticationException e) {

private void handleError(AuthenticationException error, Promise promise) {
if(error.isBrowserAppNotAvailable()) {
promise.reject("a0.browser_not_available", "No Browser application is installed.");
promise.reject("a0.browser_not_available", "No Browser application is installed.", error);
return;
}
if(error.isCanceled()) {
promise.reject("a0.session.user_cancelled", "User cancelled the Auth");
promise.reject("a0.session.user_cancelled", "User cancelled the Auth", error);
return;
}
promise.reject("a0.response.invalid", error.getMessage());
if(error.isNetworkError()) {
promise.reject("a0.network_error", "Network error", error);
return;
}
if(error.isIdTokenValidationError()) {
promise.reject("a0.session.invalid_idtoken", "Error validating ID Token", error);
return;
}
promise.reject(error.getCode(), error.getMessage(), error);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,11 @@ target 'Auth0Example' do
:mac_catalyst_enabled => false
)
__apply_Xcode_12_5_M1_post_install_workaround(installer)

installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
end
end
poovamraj marked this conversation as resolved.
Show resolved Hide resolved
end
end
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- A0Auth0 (3.0.0):
- A0Auth0 (3.0.1):
- Auth0 (= 2.5.0)
- JWTDecode (= 3.1.0)
- React-Core
Expand Down Expand Up @@ -423,7 +423,7 @@ PODS:
- React-logger (= 0.71.10)
- React-perflogger (= 0.71.10)
- SimpleKeychain (1.1.0)
- SocketRocket (0.6.0)
- SocketRocket (0.6.1)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -584,7 +584,7 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
A0Auth0: 1ef7e745d9cd80340fc81b9de7f712f0b467cd21
A0Auth0: 9c3222f9a2938e7dd61002108134fa4c39b66298
Auth0: 72f19ad566fdf57f07bf37f828afd0c1570769a5
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
Expand Down Expand Up @@ -634,10 +634,10 @@ SPEC CHECKSUMS:
React-runtimeexecutor: a9a1cd79996c9a0846e3232ecb25c64e1cc0172e
ReactCommon: 65718685d4095d06b4b1af8042e12f1df2925c31
SimpleKeychain: f8707c8e97b38c6a6e687b17732afc9bcef06439
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: e7ea9e590e27460d28911403b894722354d73479
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 78e8dab006d0d9a82e41a924fda07d925d4623c7
PODFILE CHECKSUM: 8b76cdfa2c2f558cb3fb9288d07f13c3d579c8c9

COCOAPODS: 1.12.1
18 changes: 15 additions & 3 deletions ios/NativeBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ extension WebAuthError {
case .noAuthorizationCode: code = "NO_AUTHORIZATION_CODE"
case .pkceNotAllowed: code = "PKCE_NOT_ALLOWED"
case .idTokenValidationFailed: code = "ID_TOKEN_VALIDATION_FAILED"
case .other: code = "OTHER"
case .other: if let cause = self.cause as? AuthenticationError {
code = cause.code
} else {
code = "OTHER"
}
default: code = "UNKNOWN"
}
return code
Expand All @@ -213,10 +217,18 @@ extension CredentialsManagerError {
switch self {
case .noCredentials: code = "NO_CREDENTIALS"
case .noRefreshToken: code = "NO_REFRESH_TOKEN"
case .renewFailed: code = "RENEW_FAILED"
case .renewFailed: if let cause = self.cause as? AuthenticationError {
code = cause.code
} else {
code = "RENEW_FAILED"
}
case .storeFailed: code = "STORE_FAILED"
case .biometricsFailed: code = "BIOMETRICS_FAILED"
case .revokeFailed: code = "REVOKE_FAILED"
case .revokeFailed: if let cause = self.cause as? AuthenticationError {
code = cause.code
} else {
code = "REVOKE_FAILED"
}
case .largeMinTTL: code = "LARGE_MIN_TTL"
default: code = "UNKNOWN"
}
Expand Down
Loading