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.
Extends
Section titled “Extends”Error
Type Parameters
Section titled “Type Parameters”E = unknown
The type of the error value from the canister
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CanisterError<
E>(err):CanisterError<E>
Defined in: core/src/errors/index.ts:211
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”CanisterError<E>
Overrides
Section titled “Overrides”Error.constructor
Properties
Section titled “Properties”
readonlyerr:E
Defined in: core/src/errors/index.ts:201
The raw error value from the canister
readonlycode:string
Defined in: core/src/errors/index.ts:203
The error code, extracted from the error object or variant key
details
Section titled “details”
readonlydetails: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.
Methods
Section titled “Methods”toJSON()
Section titled “toJSON()”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.
Returns
Section titled “Returns”unknown
isApiError()
Section titled “isApiError()”
staticisApiError(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.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”error is ApiError<unknown, unknown>
create()
Section titled “create()”
staticcreate(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.
Parameters
Section titled “Parameters”unknown
message?
Section titled “message?”string
Returns
Section titled “Returns”CanisterError