diff options
author | Matthew Miller <matthew@millerti.me> | 2023-02-28 22:30:56 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2023-02-28 22:40:15 -0800 |
commit | edd8e54f6d1c52e0315cd25d82e943348a9bd622 (patch) | |
tree | e5a9574f49dab2422ee49337e71d38d6361e67f0 /packages/browser/src/helpers/identifyAuthenticationError.ts | |
parent | 50bf90ffa88e2f327d400cb175b1f1a0c7d7588e (diff) |
Update error identification with error codes
Diffstat (limited to 'packages/browser/src/helpers/identifyAuthenticationError.ts')
-rw-r--r-- | packages/browser/src/helpers/identifyAuthenticationError.ts | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/packages/browser/src/helpers/identifyAuthenticationError.ts b/packages/browser/src/helpers/identifyAuthenticationError.ts index d5ba5fa..e617a7d 100644 --- a/packages/browser/src/helpers/identifyAuthenticationError.ts +++ b/packages/browser/src/helpers/identifyAuthenticationError.ts @@ -20,32 +20,47 @@ export function identifyAuthenticationError({ if (error.name === 'AbortError') { if (options.signal === new AbortController().signal) { // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16) - return new WebAuthnError('Authentication ceremony was sent an abort signal', error); + return new WebAuthnError({ + message: 'Authentication ceremony was sent an abort signal', + code: 'ERROR_CEREMONY_ABORTED', + cause: error, + }); } } else if (error.name === 'NotAllowedError') { /** * Pass the error directly through. Platforms are overloading this error beyond what the spec * defines and we don't want to overwrite potentially useful error messages. */ + return new WebAuthnError({ + message: error.message, + code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY', + cause: error, + }); } else if (error.name === 'SecurityError') { const effectiveDomain = window.location.hostname; if (!isValidDomain(effectiveDomain)) { // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5) - return new WebAuthnError(`${window.location.hostname} is an invalid domain`, error); + return new WebAuthnError({ + message: `${window.location.hostname} is an invalid domain`, + code: 'ERROR_INVALID_DOMAIN', + cause: error, + }); } else if (publicKey.rpId !== effectiveDomain) { // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6) - return new WebAuthnError( - `The RP ID "${publicKey.rpId}" is invalid for this domain`, - error, - ); + return new WebAuthnError({ + message: `The RP ID "${publicKey.rpId}" is invalid for this domain`, + code: 'ERROR_INVALID_RP_ID', + cause: error, + }); } } else if (error.name === 'UnknownError') { // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1) // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12) - return new WebAuthnError( - 'The authenticator was unable to process the specified options, or could not create a new assertion signature', - error, - ); + return new WebAuthnError({ + message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature', + code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR', + cause: error, + }); } return error; |