success before using data, logging errors for visibility in the UI, and matching specific error codes when you need different recovery logic per failure type.
Response Structure
All SDK methods return response objects:Checking Results
Always checksuccess before using data:
Uncaught Exceptions
Uncaught exceptions inrun or unwind are caught by the SDK. The execution is marked as failed and the error is logged. You don’t need to wrap SDK method calls in try/catch blocks unless you need to handle for a specific error.
When to Use Try/Catch
Only use try/catch for your own logic that might throw (parsing, calculations with external data, custom recovery). Don’t use it for SDK method calls — just check.success instead.
Swap Error Codes
Swap methods (agent.swidge.quote(), agent.swidge.execute()) return typed error codes in the error field:
| Error Code | Cause | Solution |
|---|---|---|
QUOTE_TIMEOUT | Quote request timed out | Retry after a brief delay |
ALL_ENGINES_FAILED | Every routing engine returned an error | Check input parameters; the route may not be available |
NO_COMPATIBLE_ENGINES | No engine supports this token pair or route | Verify token addresses and network IDs |
ENGINE_API_ERROR | Upstream routing engine returned an error | Retry; if persistent, the engine may be temporarily down |
PRICE_IMPACT_TOO_HIGH | Price impact exceeds acceptable threshold | Reduce swap amount or increase slippage tolerance |
INSUFFICIENT_BALANCE | Wallet balance too low for this swap | Check positions before quoting |
INTERNAL_ERROR | Unexpected internal error | Log and retry; contact support if persistent |
Hyperliquid Error Codes
Hyperliquid methods (agent.platforms.hyperliquid.*) return error messages in the error field. See Hyperliquid: Common Errors for the full table.
Polymarket Error Codes
Polymarket methods (agent.platforms.polymarket.*) return typed error codes:
| Error Code | Cause | Solution |
|---|---|---|
ORDERBOOK_NOT_FOUND | No orderbook for the given token | Verify tokenId from Polymarket |
MARKET_NOT_FOUND | Market does not exist | Check that the market hasn’t been resolved or removed |
TOKEN_NOT_IN_MARKET | Token ID not associated with market | Use correct tokenId for the market |
INSUFFICIENT_LIQUIDITY | Not enough liquidity to fill order | Reduce order size or wait for more liquidity |
INSUFFICIENT_BALANCE | Wallet USDC balance too low for this order | Check balances before placing orders |
ORDER_REJECTED | Order was rejected by the exchange | Check order parameters (size, side) |
UPSTREAM_API_ERROR | Polymarket API returned an error | Retry; check Polymarket status |
UPSTREAM_HTTP_ERROR | HTTP error from Polymarket | Retry with backoff |
UPSTREAM_INVALID_RESPONSE | Unexpected response format from Polymarket | Likely a temporary API issue; retry |
NETWORK_ERROR | Network connectivity issue | Retry with backoff |
CREDENTIALS_ERROR | Invalid or missing API credentials | Ensure session is active and wallet is valid |
INTERNAL_ERROR | Unexpected internal error | Log and retry; contact support if persistent |
Transaction Reverts
WhenwaitForConfirmation is true (the default), the SDK polls a public RPC for the transaction receipt after broadcast. If the transaction was mined but reverted onchain, the response returns success: false:
signAndSend, swidge.execute, polymarket.marketOrder, and polymarket.redeemPositions. Set waitForConfirmation: false to skip receipt polling and return immediately after broadcast.
General Error Patterns
| Error | Cause | Solution |
|---|---|---|
| ”Key not found” | Memory key doesn’t exist | Check if key exists first or handle missing keys |
| ”Invalid request” | Bad parameters to SDK method | Validate inputs before calling SDK methods |
| ”Transaction failed” | Insufficient balance/gas or revert | Check balances via getCurrentPositions() before transactions |
Tips
- Always check
successbefore usingdata - Log errors with
error: true/error=Trueso they show up in the UI - Return early on errors instead of continuing
- Validate inputs before making SDK calls
- Match against specific error codes when you need different handling per failure type
See Also
- Troubleshooting — Common issues and solutions for CLI, SDK, and platform-specific problems
- Logging — Log errors with
error: trueso they appear in the UI