summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/__jest__/generateCustomError.ts
blob: 3c0a8170a149c33735a847baf4fa263e2de81be0 (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;
}