Handling Passlock errors
Errors happen. Our safe API makes it easy to reason about potential errors:
import { Passlock, isPasskeyUnsupportedError } from "@passlock/browser";
const passlock = new Passlock({ tenancyId });
const result = await passlock.registerPasskey({ ... });
if (result.success) { // successful responses are exposed via the value property console.log(result.value);}
if (result.failure) { // failures are exposed via the error property // use a type guard to narrow the error type if (isPasskeyUnsupportedError(result.error)) { // alternatively narrow using the `_tag` discriminator } else if (result.error._tag === "@error/DuplicatePasskey") { ... }}| Property | Description |
|---|---|
| success | Indicates whether the operation was successful. |
| failure | Indicates whether the operation failed. |
| value | The resulting value of the operation, if successful. |
| error | The error that occurred, if the operation failed. |
| _tag | Discriminator, used to narrow the error type. |