Skip to content
IC Reactor

CanisterError

Defined in: core/src/errors/index.ts:199

Error thrown when the canister returns an Err result. The err property contains the typed error value from the canister.

It also supports accessing code, message, and details directly if the error object follows the common API error format or is a variant.

  • Error

E = unknown

The type of the error value from the canister

new CanisterError<E>(err): CanisterError<E>

Defined in: core/src/errors/index.ts:211

E

CanisterError<E>

Error.constructor

readonly err: E

Defined in: core/src/errors/index.ts:201

The raw error value from the canister


readonly code: string

Defined in: core/src/errors/index.ts:203

The error code, extracted from the error object or variant key


readonly details: CanisterErrorDetails<E>

Defined in: core/src/errors/index.ts:209

The details field of an error value with a text code, as the canister returned it; undefined for any other error value. Its type follows the error value’s: see CanisterErrorDetails.

toJSON(): unknown

Defined in: core/src/errors/index.ts:276

JSON form, with any BigInt in err written as a string. err itself keeps its typed value.

unknown


static isApiError(error): error is ApiError<unknown, unknown>

Defined in: core/src/errors/index.ts:287

Type guard to check if an error object follows the API error format.

It checks only that code, message and details are present, so it narrows message and details to unknown: read their types from the canister’s Candid type, or check them before use.

unknown

error is ApiError<unknown, unknown>


static create(error, message?): CanisterError

Defined in: core/src/errors/index.ts:301

Factory method to create a CanisterError from any error. If the input is already a CanisterError, it returns it. If it’s an API error shape, it wraps it. Otherwise, it creates a new CanisterError with an “UNKNOWN_ERROR” code.

unknown

string

CanisterError