Skip to content

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") {
...
}
}
PropertyDescription
successIndicates whether the operation was successful.
failureIndicates whether the operation failed.
valueThe resulting value of the operation, if successful.
errorThe error that occurred, if the operation failed.
_tagDiscriminator, used to narrow the error type.