summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/__jest__/generateCustomError.ts
blob: 55f6acf4fc58dcaa846d3486a80a509d44809bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 * Create "custom errors" to help emulate WebAuthn API errors
 */
type WebAuthnErrorName =
  | 'AbortError'
  | 'ConstraintError'
  | 'InvalidStateError'
  | 'NotAllowedError'
  | 'NotSupportedError'
  | 'SecurityError'
  | 'UnknownError';

export function generateCustomError(name: WebAuthnErrorName, message = ''): Error {
  const customError = new Error();
  customError.name = name;
  customError.message = message;
  return customError;
}