Skip to content
New issue

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

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

Already on GitHub? # 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
8 changes: 4 additions & 4 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,7 +634,7 @@ SPEC CHECKSUMS:
React-runtimeexecutor: a9a1cd79996c9a0846e3232ecb25c64e1cc0172e
ReactCommon: 65718685d4095d06b4b1af8042e12f1df2925c31
SimpleKeychain: f8707c8e97b38c6a6e687b17732afc9bcef06439
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: e7ea9e590e27460d28911403b894722354d73479
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
12 changes: 10 additions & 2 deletions ios/NativeBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ extension WebAuthError {
case .pkceNotAllowed: code = "PKCE_NOT_ALLOWED"
case .idTokenValidationFailed: code = "ID_TOKEN_VALIDATION_FAILED"
case .other: code = "OTHER"
default: code = "UNKNOWN"
default: if let cause = self.cause as? AuthenticationError {
code = cause.code
} else {
code = "UNKNOWN"
}
}
return code
}
Expand All @@ -218,7 +222,11 @@ extension CredentialsManagerError {
case .biometricsFailed: code = "BIOMETRICS_FAILED"
case .revokeFailed: code = "REVOKE_FAILED"
case .largeMinTTL: code = "LARGE_MIN_TTL"
default: code = "UNKNOWN"
default: if let cause = self.cause as? AuthenticationError {
code = cause.code
} else {
code = "UNKNOWN"
}
}
return code
}
Expand Down