MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 138 forks source link

Differentiate browser / server errors by name #190

Closed felixmosh closed 2 years ago

felixmosh commented 2 years ago

Hi, since v5, looks like the error.name is always WebAuthnError, so if I want to show a translated message on my app, the only way to distinguish between errors is to check the message (which may change).

Previously this code (which is taken from the examples)

try {
...
} catch(error) {
  if (error.name === 'InvalidStateError') {
    throw ['WEB_AUTHN.ERROR.DEVICE_ALREADY_EXIST'];
  } else if (error.name === 'NotAllowedError') {
    throw ['WEB_AUTHN.ERROR.NOT_ALLOWED'];
  }
}

Do you think that it is better to change the name of the error? I can prepare a quick PR for it.

MasterKale commented 2 years ago

The fix for this is now available in @simplewebauthn/browser@5.1.0 🚀