Errors
KryptWardenPaymentError, its codes, and what to do about each.
When the policy stops a payment, kw.fetch() throws a KryptWardenPaymentError. Network failures that have nothing to do with payment behave like normal fetch.
class KryptWardenPaymentError extends Error {
readonly code: KryptWardenErrorCode;
readonly requestId: string; // hex, unique per payment attempt
readonly agentPublicKey: string;
readonly walletAddress: string;
readonly seller?: string;
readonly amountStroops?: string;
readonly amountUsdc?: string;
readonly holdId?: number;
readonly txHash?: string;
readonly contractErrorCode?: number; // see Contract errors
}err.message starts with the code in brackets, for example [REJECTED_BUDGET] Payment of 2.00 USDC exceeds remaining daily budget (1.55 USDC).
Codes
| Code | When | What to do |
|---|---|---|
REJECTED_BUDGET | The payment would take today's spend plus open holds over the daily budget | Wait for the next UTC day, or ask the owner to raise the budget |
REJECTED_SELLER | The payTo address isn't on the agent's allow-list | Ask the owner to add the seller, or use another one |
HOLD_DENIED | The owner denied the hold | Don't retry automatically |
HOLD_EXPIRED | Nobody decided before the hold timeout, or maxHoldWaitMs ran out | Retry later, or notify the owner sooner with onHoldCreated |
AGENT_PAUSED | The owner paused this agent | Stop paid work until it's resumed |
AGENT_REVOKED | The key isn't registered on this wallet, or was revoked | Check walletAddress and the key; register again if needed |
AGENT_EXPIRED | The key's expires_at has passed | The owner must update the policy |
WALLET_PAUSED | The owner hit the wallet-wide kill switch | Stop paid work |
BAIT_AND_SWITCH_DETECTED | After approval, the seller's new challenge asked for a different amount, recipient or asset | Treat the seller as untrusted |
FACILITATOR_ERROR | Relayer or facilitator failure, a malformed 402, or an unsupported asset | Safe to retry with backoff |
Which refusals are recorded
For REJECTED_BUDGET, REJECTED_SELLER and the agent-state codes, the SDK asks the relayer to record a PaymentRejected event on the wallet before throwing. The owner sees the attempt in the Spend Ledger with its reason. Recording is best-effort: if the relayer is down, the payment is still refused.
Contract error mapping
When the contract itself refuses (for example a policy changed between the SDK's check and settlement), the SDK maps the contract error number to a code:
| Contract error | SDK code |
|---|---|
BudgetExceeded (115) | REJECTED_BUDGET |
SellerNotAllowed (114) | REJECTED_SELLER |
HoldExpired (120) | HOLD_EXPIRED |
HoldNotApproved (118) | HOLD_DENIED |
AgentExpired (108) | AGENT_EXPIRED |
AgentNotActive (107), AgentNotFound (106) | AGENT_REVOKED |
WalletPaused (109), OpenZeppelin pause (1000) | WALLET_PAUSED |
| anything else | FACILITATOR_ERROR |
The original number is kept in err.contractErrorCode. All numbers are listed in Contract errors.