-
Notifications
You must be signed in to change notification settings - Fork 233
Expose generic error codes for CredentialsManagerError #1076
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
Changes from 1 commit
4ebe3c0
cdfe8a2
1f1fe55
4e14799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,43 @@ | |
|
|
||
| public class A0Auth0Module extends ReactContextBaseJavaModule implements ActivityEventListener { | ||
|
|
||
| public static final Map<CredentialsManagerException, String> ERROR_CODE_MAP = new HashMap<>() {{ | ||
| put(CredentialsManagerException.Companion.getINVALID_CREDENTIALS(), "INVALID_CREDENTIALS"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Enums are internal in the underlying android SDK right now and we cannot access them. |
||
| put(CredentialsManagerException.Companion.getNO_CREDENTIALS(), "NO_CREDENTIALS"); | ||
| put(CredentialsManagerException.Companion.getNO_REFRESH_TOKEN(), "NO_REFRESH_TOKEN"); | ||
| put(CredentialsManagerException.Companion.getRENEW_FAILED(), "RENEW_FAILED"); | ||
| put(CredentialsManagerException.Companion.getSTORE_FAILED(), "STORE_FAILED"); | ||
| put(CredentialsManagerException.Companion.getREVOKE_FAILED(), "REVOKE_FAILED"); | ||
| put(CredentialsManagerException.Companion.getLARGE_MIN_TTL(), "LARGE_MIN_TTL"); | ||
| put(CredentialsManagerException.Companion.getINCOMPATIBLE_DEVICE(), "INCOMPATIBLE_DEVICE"); | ||
| put(CredentialsManagerException.Companion.getCRYPTO_EXCEPTION(), "CRYPTO_EXCEPTION"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NO_ACTIVITY(), "BIOMETRIC_NO_ACTIVITY"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_STATUS_UNKNOWN(), "BIOMETRIC_ERROR_STATUS_UNKNOWN"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_UNSUPPORTED(), "BIOMETRIC_ERROR_UNSUPPORTED"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_HW_UNAVAILABLE(), "BIOMETRIC_ERROR_HW_UNAVAILABLE"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NONE_ENROLLED(), "BIOMETRIC_ERROR_NONE_ENROLLED"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NO_HARDWARE(), "BIOMETRIC_ERROR_NO_HARDWARE"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED(), "BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_AUTHENTICATION_CHECK_FAILED(), "BIOMETRIC_AUTHENTICATION_CHECK_FAILED"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_DEVICE_CREDENTIAL_NOT_AVAILABLE(), "BIOMETRIC_ERROR_DEVICE_CREDENTIAL_NOT_AVAILABLE"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_STRONG_AND_DEVICE_CREDENTIAL_NOT_AVAILABLE(), "BIOMETRIC_ERROR_STRONG_AND_DEVICE_CREDENTIAL_NOT_AVAILABLE"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL(), "BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NEGATIVE_BUTTON(), "BIOMETRIC_ERROR_NEGATIVE_BUTTON"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_HW_NOT_PRESENT(), "BIOMETRIC_ERROR_HW_NOT_PRESENT"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NO_BIOMETRICS(), "BIOMETRIC_ERROR_NO_BIOMETRICS"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_USER_CANCELED(), "BIOMETRIC_ERROR_USER_CANCELED"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_LOCKOUT_PERMANENT(), "BIOMETRIC_ERROR_LOCKOUT_PERMANENT"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_VENDOR(), "BIOMETRIC_ERROR_VENDOR"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_LOCKOUT(), "BIOMETRIC_ERROR_LOCKOUT"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_CANCELED(), "BIOMETRIC_ERROR_CANCELED"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_NO_SPACE(), "BIOMETRIC_ERROR_NO_SPACE"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_TIMEOUT(), "BIOMETRIC_ERROR_TIMEOUT"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_ERROR_UNABLE_TO_PROCESS(), "BIOMETRIC_ERROR_UNABLE_TO_PROCESS"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRICS_INVALID_USER(), "BIOMETRICS_INVALID_USER"); | ||
| put(CredentialsManagerException.Companion.getBIOMETRIC_AUTHENTICATION_FAILED(), "BIOMETRIC_AUTHENTICATION_FAILED"); | ||
| put(CredentialsManagerException.Companion.getAPI_ERROR(), "API_ERROR"); | ||
| put(CredentialsManagerException.Companion.getNO_NETWORK(), "NO_NETWORK"); | ||
| }}; | ||
| private static final String CREDENTIAL_MANAGER_ERROR_CODE = "a0.invalid_state.credential_manager_exception"; | ||
| private static final String INVALID_DOMAIN_URL_ERROR_CODE = "a0.invalid_domain_url"; | ||
| private static final String BIOMETRICS_AUTHENTICATION_ERROR_CODE = "a0.invalid_options_biometrics_authentication"; | ||
|
|
@@ -122,18 +159,24 @@ public void onSuccess(Credentials credentials) { | |
|
|
||
| @Override | ||
| public void onFailure(@NonNull CredentialsManagerException e) { | ||
| promise.reject(CREDENTIAL_MANAGER_ERROR_CODE, e.getMessage(), e); | ||
| String errorCode = deduceErrorCode(e); | ||
| promise.reject(errorCode, e.getMessage(), e); | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| private String deduceErrorCode(@NonNull CredentialsManagerException e) { | ||
| return ERROR_CODE_MAP.getOrDefault(e, CREDENTIAL_MANAGER_ERROR_CODE); | ||
| } | ||
|
|
||
| @ReactMethod | ||
| public void saveCredentials(ReadableMap credentials, Promise promise) { | ||
| try { | ||
| this.secureCredentialsManager.saveCredentials(CredentialsParser.fromMap(credentials)); | ||
| promise.resolve(true); | ||
| } catch (CredentialsManagerException e) { | ||
| promise.reject(CREDENTIAL_MANAGER_ERROR_CODE, e.getMessage(), e); | ||
| String errorCode = deduceErrorCode(e); | ||
| promise.reject(errorCode, e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| class BaseError extends Error { | ||
| constructor(name: string, message: string) { | ||
| generic_error_code: string; | ||
|
||
| constructor(name: string, message: string, generic_error_code?: string) { | ||
| super(); | ||
| if (Error.captureStackTrace) { | ||
| Error.captureStackTrace(this, this.constructor); | ||
| } | ||
| this.name = name; | ||
| this.message = message; | ||
| this.generic_error_code = generic_error_code || ''; | ||
| } | ||
| } | ||
|
|
||
| export default BaseError; | ||
| export default BaseError; | ||
Uh oh!
There was an error while loading. Please reload this page.