Overview
The SDK uses:NexusError— Typed error class with structured dataERROR_CODES— Enumeration of all possible error codes- Hooks — User approval mechanisms for intents and allowances
- Event callbacks — Real-time operation progress tracking
NexusError Class
All SDK errors are thrown asNexusError instances:
NexusError Structure
Error Codes Reference
The SDK defines comprehensive error codes grouped by category:User Actions
| Code | Description | Handling |
|---|---|---|
USER_DENIED_INTENT | User rejected the intent | Silent - user cancelled |
USER_DENIED_ALLOWANCE | User rejected token approval | Silent - user cancelled |
USER_DENIED_INTENT_SIGNATURE | User rejected signature | Silent - user cancelled |
USER_DENIED_SIWE_SIGNATURE | User rejected SIWE signature | Silent - user cancelled |
Balance & Funds
| Code | Description | Handling |
|---|---|---|
INSUFFICIENT_BALANCE | Not enough tokens | Show balance, suggest deposit |
NO_BALANCE_FOR_ADDRESS | No balance found | Verify address |
Validation
| Code | Description | Handling |
|---|---|---|
INVALID_INPUT | Invalid parameters | Check input values |
INVALID_ADDRESS_LENGTH | Wrong address length | Verify address format |
INVALID_VALUES_ALLOWANCE_HOOK | Invalid allowance values | Check allow() arguments |
TOKEN_NOT_SUPPORTED | Token not supported | Use supported token |
Initialization
| Code | Description | Handling |
|---|---|---|
SDK_NOT_INITIALIZED | SDK not initialized | Call initialize() first |
SDK_INIT_STATE_NOT_EXPECTED | Unexpected init state | Re-initialize SDK |
WALLET_NOT_CONNECTED | No wallet connected | Connect wallet |
CONNECT_ACCOUNT_FAILED | Failed to connect | Retry connection |
Chain & Network
| Code | Description | Handling |
|---|---|---|
CHAIN_NOT_FOUND | Chain ID not found | Use supported chain |
CHAIN_DATA_NOT_FOUND | Chain data unavailable | Check network connection |
VAULT_CONTRACT_NOT_FOUND | Vault contract missing | Contact support |
ENVIRONMENT_NOT_SUPPORTED | Environment not supported | Use mainnet/testnet |
Transactions
| Code | Description | Handling |
|---|---|---|
TRANSACTION_TIMEOUT | Transaction timed out | Retry or check explorer |
TRANSACTION_REVERTED | Transaction reverted | Check contract/params |
TRANSACTION_CHECK_ERROR | Error checking transaction | Retry |
FETCH_GAS_PRICE_FAILED | Failed to fetch gas price | Retry |
Operations
| Code | Description | Handling |
|---|---|---|
SIMULATION_FAILED | Simulation failed | Check parameters |
QUOTE_FAILED | Failed to get quote | Retry |
SWAP_FAILED | Swap operation failed | Retry or adjust params |
REFUND_FAILED | Refund request failed | Contact support |
Intent & Solver
| Code | Description | Handling |
|---|---|---|
LIQUIDITY_TIMEOUT | Solver liquidity timeout | Retry later |
RATES_CHANGED_BEYOND_TOLERANCE | Price moved too much | Refresh and retry |
RFF_FEE_EXPIRED | Request expired | Retry operation |
SLIPPAGE_EXCEEDED_ALLOWANCE | Slippage exceeded | Increase allowance |
Handling Specific Errors
User Cancellations
Insufficient Balance
Transaction Timeout
Price Changes (Slippage)
Intent Hook
The intent hook is called when the SDK needs user approval for bridge/transfer operations:Intent Refresh
You can refresh the intent with different source chains:Intent Data Structure
Allowance Hook
The allowance hook is called when token approvals are needed:Allowance Approval Strategies
Allowance Data Structure
Swap Intent Hook
Called when user approval is needed for swap operations:Error Logging and Reporting
Serialize Errors for Logging
Custom Error Logger
Best Practices
Always Set Hooks
Set up intent and allowance hooks before any operations. Without hooks, the SDK will wait indefinitely for user approval.
Distinguish User Cancellations
Don’t show error messages for
USER_DENIED_* errors - these are intentional user actions, not failures.Provide Context
Show users why an error occurred and what they can do about it. Use the error’s
data.details for specific information.Handle Async Errors
Bridge and swap operations can take time. Provide progress updates and handle timeout errors gracefully.
Log Errors Properly
Use
error.toJSON() to serialize errors for logging. Include operation context and user actions for debugging.Real-World Error Handler
Complete example from production:Next Steps
Bridge Operations
Apply error handling to bridge operations
Swap Operations
Handle swap-specific errors
Execute Contracts
Error handling for contract execution
API Reference
Complete API documentation