Skip to content

API ReferenceErrorsClass

BaseError

Base class for the SDK’s typed errors. Every error class in this reference extends it, so instanceof BaseError tells an SDK diagnosis apart from any other exception.

An SDK error often wraps the error that caused it, such as a wallet or RPC error, as its standard cause. Use BaseError.walk to find a specific error class anywhere in that chain.

Extends

  • Error

Extended by

Constructors

Constructor

new BaseError(message, cause?): BaseError;

Parameters

ParameterType
messagestring
cause?unknown

Returns

BaseError

Overrides

Error.constructor;

Methods

walk()

walk<T>(errorType): T | undefined;

Finds an error of the given class in this error’s cause chain. The search starts with this error itself, then follows each cause in turn.

Type Parameters

Type ParameterDescription
T extends ErrorThe error class being searched for.

Parameters

ParameterTypeDescription
errorType(…args) => TThe error class to find, such as UserRejectedRequestError.

Returns

T | undefined

The first error in the chain that is an instance of errorType, or undefined if there is none.

Example

const rejected = error.walk(UserRejectedRequestError);
if (rejected) return; // the user declined in their wallet