summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/identifyAuthenticationError.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2023-03-15 18:46:41 -0700
committerGitHub <noreply@github.com>2023-03-15 18:46:41 -0700
commitcc6b4e83d0c8087f78c1851a5b0f60a1d7223ec6 (patch)
treeca62fa0690780c7dace0d3a956e10110c5d5e277 /packages/browser/src/helpers/identifyAuthenticationError.ts
parent70f7e79b24237308398334df834dd4cf2d398512 (diff)
parentac97005f39974154dc2af9514294bbe217a252f6 (diff)
Merge pull request #367 from MasterKale/feat/better-errors
feat/better-errors
Diffstat (limited to 'packages/browser/src/helpers/identifyAuthenticationError.ts')
-rw-r--r--packages/browser/src/helpers/identifyAuthenticationError.ts37
1 files changed, 26 insertions, 11 deletions
diff --git a/packages/browser/src/helpers/identifyAuthenticationError.ts b/packages/browser/src/helpers/identifyAuthenticationError.ts
index 600a2d6..e617a7d 100644
--- a/packages/browser/src/helpers/identifyAuthenticationError.ts
+++ b/packages/browser/src/helpers/identifyAuthenticationError.ts
@@ -1,5 +1,5 @@
import { isValidDomain } from './isValidDomain';
-import { WebAuthnError } from './structs';
+import { WebAuthnError } from './webAuthnError';
/**
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
@@ -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', 'AbortError');
+ 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`, 'SecurityError');
+ 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`,
- 'SecurityError',
- );
+ 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',
- 'UnknownError',
- );
+ 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;