JavaScript SDK

Errors

The error classes the SDK returns, their codes, and how requests are retried.

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.

ClasscodeWhen
BaseHttpErrorHTTP status (number)The API answered with an error status. json holds the body: json.error is the message, json.error_code the machine code.
SsoRequiredError403The email domain must sign in with SAML. Has ssoLoginUrl and domain.
TechnicalErrornone, slug technical_errorSomething failed that the user cannot fix, such as a failed user lookup.
IdentifierNotRecognizedErroridentifier-not-recognizedsignIn, verifyOtp: no such user.
IdentifierAlreadyExistsErroridentifier-already-existssignUp: the user exists.
IdentifierInvalidErroridentifier-invalidThe identifier is not valid.
NewDeviceErrornew-deviceNo passkey of the user on this device.
LoginRequiredErrorlogin-requiredA call needs a signed-in user.
InvalidAuthTokenErrorinvalid-auth-tokenNo valid access token, or the API refused it with 401.
UnknownSignInErrorunknown-sign-inThe session was stored but the user could not be read.
InvalidMagicLinkErrorinvalid-magic-linkNo token, a token that does not decode, or a missing pending step token.
MagicLinkWindowClosedErrormagic-link-window-closedThe link was opened too long ago for this device to finish.
WebAuthnErrorERROR_*A passkey prompt failed. See below.
PasskeysUnavailableErrorERROR_PASSKEYS_UNAVAILABLERegistration 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#

HelperReturns 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:

CodeMeaning
ERROR_CEREMONY_ABORTEDThe prompt was cancelled by an abort signal.
ERROR_INVALID_DOMAINThe page's hostname is not a valid domain.
ERROR_INVALID_RP_IDThe relying party ID does not match this domain.
ERROR_INVALID_USER_ID_LENGTHThe user ID is not 1 to 64 bytes.
ERROR_MALFORMED_PUBKEYCREDPARAMSNo public-key entry in the options.
ERROR_AUTHENTICATOR_GENERAL_ERRORThe authenticator failed.
ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORTThe authenticator cannot store a discoverable credential.
ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORTThe authenticator cannot verify the user.
ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTEREDThis authenticator is already registered.
ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALGNo supported algorithm.
ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTYThe browser's own error; see error.cause.
ERROR_PASSKEYS_UNAVAILABLEThe 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.