summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/__jest__/generateCustomError.ts
blob: 25609faddaa2669032018b909e658116e71e0f0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * 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;
}