Skip to content

isCanisterError

isCanisterError<E>(error): error is CanisterError<E>

Defined in: errors/index.ts:152

Type guard to check if an error is a CanisterError. Preserves the generic type E from the input when used in type narrowing.

E

CallError | CanisterError<E>

error is CanisterError<E>

// err is typed as CanisterError<TransferError> | CallError
if (isCanisterError(err)) {
// err.err is typed as TransferError (preserved!)
console.log(err.err)
}

isCanisterError(error): error is CanisterError<unknown>

Defined in: errors/index.ts:155

Type guard to check if an error is a CanisterError. Preserves the generic type E from the input when used in type narrowing.

unknown

error is CanisterError<unknown>

// err is typed as CanisterError<TransferError> | CallError
if (isCanisterError(err)) {
// err.err is typed as TransferError (preserved!)
console.log(err.err)
}