From d088c064064c4612d7c8549354c8b47a7ba9abe5 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 28 Feb 2023 22:00:44 -0800 Subject: Prepare to expand WebAuthnError --- packages/browser/src/helpers/webAuthnError.ts | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/browser/src/helpers/webAuthnError.ts (limited to 'packages/browser/src/helpers/webAuthnError.ts') diff --git a/packages/browser/src/helpers/webAuthnError.ts b/packages/browser/src/helpers/webAuthnError.ts new file mode 100644 index 0000000..aad98ff --- /dev/null +++ b/packages/browser/src/helpers/webAuthnError.ts @@ -0,0 +1,30 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +/** + * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented + * errors in the spec was raised after calling `navigator.credentials.create()` or + * `navigator.credentials.get()`: + * + * - `AbortError` + * - `ConstraintError` + * - `InvalidStateError` + * - `NotAllowedError` + * - `NotSupportedError` + * - `SecurityError` + * - `TypeError` + * - `UnknownError` + * + * Error messages were determined through investigation of the spec to determine under which + * scenarios a given error would be raised. + */ +export class WebAuthnError extends Error { + constructor(message: string, cause: Error, name?: string) { + /** + * `cause` is supported in evergreen browsers, but not IE10, so this ts-ignore is to + * help Rollup complete the ES5 build. + */ + // @ts-ignore + super(message, { cause }) + // this.name = name ?? cause.name; + this.name = name ?? cause.name; + } +} -- cgit v1.2.3