Client methods return { data, error } and do not throw on API errors. A few helpers throw, and say so on their pages (identifierExists, isAnyDeviceRegistered, authzStartStepUp, toSqlWhere, clientIp validation).
Classes#
All errors extend ScuteError, which extends Error with code?: string | number, slug?: string and cause?: Error.
| Class | code | When |
|---|---|---|
| BaseHttpError | HTTP status (number) | The API answered with an error status. json holds the body: json.error is the message, json.error_code the machine code. |
| SsoRequiredError | 403 | The email domain must sign in with SAML. Has ssoLoginUrl and domain. |
| TechnicalError | none, slug technical_error | Something failed that the user cannot fix, such as a failed user lookup. |
| IdentifierNotRecognizedError | identifier-not-recognized | signIn, verifyOtp: no such user. |
| IdentifierAlreadyExistsError | identifier-already-exists | signUp: the user exists. |
| IdentifierInvalidError | identifier-invalid | The identifier is not valid. |
| NewDeviceError | new-device | No passkey of the user on this device. |
| LoginRequiredError | login-required | A call needs a signed-in user. |
| InvalidAuthTokenError | invalid-auth-token | No valid access token, or the API refused it with 401. |
| UnknownSignInError | unknown-sign-in | The session was stored but the user could not be read. |
| InvalidMagicLinkError | invalid-magic-link | No token, a token that does not decode, or a missing pending step token. |
| MagicLinkWindowClosedError | magic-link-window-closed | The link was opened too long ago for this device to finish. |
| WebAuthnError | ERROR_* | A passkey prompt failed. See below. |
| PasskeysUnavailableError | ERROR_PASSKEYS_UNAVAILABLE | Registration on a page without passkey support. |
The classes from IdentifierNotRecognizedError to MagicLinkWindowClosedError extend CustomScuteError. Each has a slug that is its code with underscores (identifier_not_recognized).
import { BaseHttpError, InvalidAuthTokenError } from "@scute/js-core";const { error } = await scute.getUser(token);if (error instanceof InvalidAuthTokenError) return res.status(401).end();if (error instanceof BaseHttpError) console.error(error.code, error.json?.error_code);A message to show#
getMeaningfulError(error) returns { isFatal: boolean, message: string }. It uses the API's message for HTTP errors (except 500, which becomes "Something went wrong."), the class message for CustomScuteError, and treats an aborted passkey prompt as not fatal.
Helpers#
| Helper | Returns true when |
|---|---|
| isSsoRequiredError(error) | The error is an SsoRequiredError. |
| needsReverification(error) | An MFA change was refused with error_code: "verification_required". See MFA. |
| passkeysAvailable() | The page can make passkeys (WebAuthn and a secure context). |
WebAuthn errors#
WebAuthnError.code is one of:
| Code | Meaning |
|---|---|
| ERROR_CEREMONY_ABORTED | The prompt was cancelled by an abort signal. |
| ERROR_INVALID_DOMAIN | The page's hostname is not a valid domain. |
| ERROR_INVALID_RP_ID | The relying party ID does not match this domain. |
| ERROR_INVALID_USER_ID_LENGTH | The user ID is not 1 to 64 bytes. |
| ERROR_MALFORMED_PUBKEYCREDPARAMS | No public-key entry in the options. |
| ERROR_AUTHENTICATOR_GENERAL_ERROR | The authenticator failed. |
| ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT | The authenticator cannot store a discoverable credential. |
| ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT | The authenticator cannot verify the user. |
| ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED | This authenticator is already registered. |
| ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG | No supported algorithm. |
| ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY | The browser's own error; see error.cause. |
| ERROR_PASSKEYS_UNAVAILABLE | The page cannot make passkeys. |
Retries#
GET, HEAD and DELETE requests are retried on 502, 503, 504 and network errors, up to 3 attempts, 500 ms apart and growing. POST, PUT and PATCH requests (codes, links, token exchanges) are never sent twice, and neither is any request that carries a refresh token.