Skip to main content

Class Hierarchy

The SDK uses typed error classes so you can catch and handle each scenario precisely. Every error extends MandateError, which itself extends the native Error.
All error classes are exported from @mandate.md/sdk:

MandateError

The base class for all SDK errors. You receive this for generic API failures that don’t fall into a more specific category. When it fires: Any non-OK API response that isn’t a 403 circuit breaker, 422 policy block, or 202 approval redirect. Common cases: network errors, 500 server errors, malformed requests. Recovery: Check statusCode to decide whether to retry. 5xx errors are transient and safe to retry with backoff. 4xx errors indicate a client-side problem.

PolicyBlockedError

Thrown when a transaction violates one or more policy rules: spend limits, allowlists, time schedules, function selectors, or other constraints configured in the dashboard. When it fires: The policy engine evaluates the transaction against the agent’s active policy and finds a violation. This covers per-transaction limits, daily/monthly quotas, address allowlists, time-of-day schedules, and function selector restrictions. Recovery: Display declineMessage to the end user if present. Adjust the transaction parameters (lower the amount, use an allowed address) or ask the agent owner to update the policy in the dashboard.
PolicyBlockedError is also exported as MandateBlockedError for backward compatibility. They are the same class.

CircuitBreakerError

Thrown when the agent’s circuit breaker is active. This is an emergency stop: all transactions are blocked until the owner resets it. When it fires: The circuit breaker trips automatically when the envelope verifier detects that a broadcast transaction does not match the parameters that were validated. An owner can also trigger it manually from the dashboard. Recovery: No programmatic fix exists. The agent owner must investigate and reset the circuit breaker in the Mandate dashboard. Your code should log the error and halt further transaction attempts.

ApprovalRequiredError

Thrown when a transaction passes policy checks but requires explicit human approval before it can proceed. When it fires: The policy includes an approval rule, and the transaction matches that rule’s criteria. The intent enters approval_pending state and waits for the owner to approve or reject via the dashboard. Recovery: Call client.waitForApproval(intentId) to poll until the owner makes a decision. The method resolves when approved, or throws if rejected or expired. You can also use MandateWallet.sendTransactionWithApproval() which handles this flow automatically.

RiskBlockedError

Thrown when the destination address is flagged by the Aegis risk scanner. When it fires: Before policy evaluation, Mandate runs the destination address through its risk scanner. If the address is associated with known exploits, sanctions, or other critical risks, this error fires. Recovery: Verify the destination address. If you believe it is a false positive, contact the Mandate risk team. Do not attempt to bypass this check.

Instanceof Checking Pattern

Use instanceof to handle each error type in a single try/catch block. Order matters: check specific subclasses before the base MandateError.

Handle Errors Guide

Step-by-step error handling patterns for production agents.

Block Reasons

Full list of blockReason codes and their meanings.

MandateClient

Low-level API client reference.