Skip to content

@lelantos-org/sdk / index / isWalletError

Function: isWalletError() ​

Call Signature ​

ts
function isWalletError(err): err is AnyWalletError;

Defined in: @lelantos-org/sdk/dist/errors/guard.d.ts:54

Type guard for SDK errors in a catch. Pass code to test one variant.

ts
try {
    await wallet.transfer({ to, amount });
} catch (err) {
    if (isWalletError(err, "INSUFFICIENT_COVER")) {
        // `err.consolidate` / `err.consolidateSum` are typed here.
        await wallet.transfer({ to, amount, autoConsolidate: true });
        return;
    }
    if (isWalletError(err, "NOTES_HELD") && err.retryable) {
        // Held by an earlier spend: `err.held` / `err.reservedUntil` are typed here.
        return scheduleRetry(err.reservedUntil);
    }
    if (isWalletError(err)) console.error(err.code, err.retryable, err.message);
    throw err;
}

Duck-typed rather than instanceof, so it still works when two copies of the SDK end up in one bundle.

Parameters ​

ParameterType
errunknown

Returns ​

err is AnyWalletError

Call Signature ​

ts
function isWalletError<C>(err, code): err is WalletErrorOf<C>;

Defined in: @lelantos-org/sdk/dist/errors/guard.d.ts:55

Type guard for SDK errors in a catch. Pass code to test one variant.

ts
try {
    await wallet.transfer({ to, amount });
} catch (err) {
    if (isWalletError(err, "INSUFFICIENT_COVER")) {
        // `err.consolidate` / `err.consolidateSum` are typed here.
        await wallet.transfer({ to, amount, autoConsolidate: true });
        return;
    }
    if (isWalletError(err, "NOTES_HELD") && err.retryable) {
        // Held by an earlier spend: `err.held` / `err.reservedUntil` are typed here.
        return scheduleRetry(err.reservedUntil);
    }
    if (isWalletError(err)) console.error(err.code, err.retryable, err.message);
    throw err;
}

Duck-typed rather than instanceof, so it still works when two copies of the SDK end up in one bundle.

Type Parameters ​

Type Parameter
C extends | "INTERNAL" | "WALLET_CONFIG" | "NETWORK_NOT_DEPLOYED" | "ENVIRONMENT" | "INVALID_ARGUMENT" | "NO_EVM_ACCOUNT" | "UNSUPPORTED_OPERATION" | "INSUFFICIENT_BALANCE" | "NOTES_HELD" | "INSUFFICIENT_COVER" | "FEE_ASSET_NOT_QUOTED" | "FEE_ABOVE_LIMIT" | "DEADLINE_PASSED" | "QUOTE_STALE" | "USER_REJECTED" | "RELAYER_REJECTED" | "SPEND_OUTCOME_UNKNOWN" | "RELAYER_TIMEOUT" | "RELAYER_FAILED" | "FMD_TIMEOUT" | "FMD_FAILED" | "QUOTER_TIMEOUT" | "QUOTER_FAILED" | "WIRE_FORMAT" | "RPC_FAILED" | "TX_REVERTED" | "TX_MINING" | "TREE_OUT_OF_SYNC" | "PROVER_FAILED" | "PROVER_UNAVAILABLE" | "PROVER_ARTIFACTS_MISSING" | "PROVER_ARTIFACTS_FAILED" | "WORKER_TIMEOUT" | "WORKER_CRASHED" | "WORKER_FAILED" | "X402_PAYMENT"

Parameters ​

ParameterType
errunknown
codeC

Returns ​

err is WalletErrorOf<C>