-
Notifications
You must be signed in to change notification settings - Fork 235
feat: unify and improve error handling across platforms #1261
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
056ce89
update(deps): update Auth0 dependency for android and iOS
subhankarmaiti c7c427c
refactor(auth): streamline error handling in CredentialsManager and u…
subhankarmaiti dcb5078
Merge branch 'master' of https://github.com/auth0/react-native-auth0 …
subhankarmaiti 9e5ebb7
feat(auth): implement platform-agnostic error handling with WebAuthEr…
subhankarmaiti d9694f7
feat(errors): enhance error handling with additional mappings for web
subhankarmaiti f52b0b7
refactor(tests): remove redundant error handling tests and update moc…
subhankarmaiti e1598b3
Revert "refactor(auth): streamline error handling in CredentialsManag…
subhankarmaiti 27949a2
feat(errors): update error codes for CredentialsManager and WebAuth t…
subhankarmaiti ed0a338
feat(errors): add new error codes for transaction handling and MFA re…
subhankarmaiti 5323a44
refactor(errors): streamline error handling in WebCredentialsManager …
subhankarmaiti 3180ee8
feat(errors): add NativeModuleError type and implement error handling…
subhankarmaiti b0a6e9c
Merge branch 'master' into SDK-5700-platform-agnostic-error
subhankarmaiti 9cfd123
adding test cases to validate each and every error from credentialman…
subhankarmaiti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export type NativeModuleError = { | ||
| code: string; | ||
| message: string; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { AuthError } from './AuthError'; | ||
|
|
||
| const ERROR_CODE_MAP: Record<string, string> = { | ||
| // --- Common Codes --- | ||
| 'a0.session.user_cancelled': 'USER_CANCELLED', | ||
| 'USER_CANCELLED': 'USER_CANCELLED', | ||
| 'access_denied': 'ACCESS_DENIED', | ||
| 'a0.network_error': 'NETWORK_ERROR', | ||
| 'a0.session.invalid_idtoken': 'ID_TOKEN_VALIDATION_FAILED', | ||
| 'ID_TOKEN_VALIDATION_FAILED': 'ID_TOKEN_VALIDATION_FAILED', | ||
| 'BIOMETRICS_CONFIGURATION_ERROR': 'BIOMETRICS_CONFIGURATION_ERROR', | ||
|
|
||
| // --- Android-specific mappings --- | ||
| 'a0.browser_not_available': 'BROWSER_NOT_AVAILABLE', | ||
| 'a0.session.failed_load': 'FAILED_TO_LOAD_URL', | ||
| 'a0.session.browser_terminated': 'BROWSER_TERMINATED', | ||
|
|
||
| // --- iOS-specific mappings --- | ||
| 'NO_BUNDLE_IDENTIFIER': 'NO_BUNDLE_IDENTIFIER', | ||
| 'TRANSACTION_ACTIVE_ALREADY': 'TRANSACTION_ACTIVE_ALREADY', | ||
| 'NO_AUTHORIZATION_CODE': 'NO_AUTHORIZATION_CODE', | ||
| 'PKCE_NOT_ALLOWED': 'PKCE_NOT_ALLOWED', | ||
| 'INVALID_INVITATION_URL': 'INVALID_INVITATION_URL', | ||
|
|
||
| // --- Web (@auth0/auth0-spa-js) mappings --- | ||
| 'cancelled': 'USER_CANCELLED', | ||
| 'state_mismatch': 'INVALID_STATE', | ||
| 'login_required': 'ACCESS_DENIED', | ||
| 'timeout': 'TIMEOUT_ERROR', | ||
| 'consent_required': 'CONSENT_REQUIRED', | ||
|
|
||
| // --- Generic Fallbacks --- | ||
| 'a0.invalid_configuration': 'INVALID_CONFIGURATION', | ||
| 'UNKNOWN': 'UNKNOWN_ERROR', | ||
| 'OTHER': 'UNKNOWN_ERROR', | ||
| }; | ||
|
|
||
|
pmathew92 marked this conversation as resolved.
|
||
| export class WebAuthError extends AuthError { | ||
| public readonly type: string; | ||
|
|
||
| constructor(originalError: AuthError) { | ||
| super(originalError.name, originalError.message, { | ||
| status: originalError.status, | ||
| code: originalError.code, | ||
| json: originalError.json, | ||
| }); | ||
|
|
||
| if ( | ||
| originalError.message.includes('state is invalid') || | ||
| originalError.code === 'state_mismatch' | ||
| ) { | ||
| this.type = 'INVALID_STATE'; | ||
| } else { | ||
| this.type = ERROR_CODE_MAP[originalError.code] || 'UNKNOWN_ERROR'; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| export { AuthError } from './AuthError'; | ||
| export { Credentials } from './Credentials'; | ||
| export { Auth0User } from './Auth0User'; | ||
| export { CredentialsManagerError } from './CredentialsManagerError'; | ||
| export { WebAuthError } from './WebAuthError'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.