RubicApiError
All API-level errors thrown by the default HTTP client are wrapped intoRubicApiError, a typed subclass of Error. You can find more information about error handling here
Fields
| Field | Type | Description |
|---|---|---|
name | 'RubicApiError' | Always 'RubicApiError' |
message | string | Same as reason — compatible with Error.message |
code | number | Numeric error code from the API |
reason | string | Human-readable error description |
data | object | undefined | Extra context returned by the API (e.g. which field failed validation) |
traceId | string | undefined | Internal request ID — include in bug reports |
Catching errors
Common error codes
| Code | Reason | Typical cause |
|---|---|---|
1001 | Insufficient liquidity | Amount too large for the selected route |
1002 | Minimum amount not reached | srcTokenAmount is below the provider minimum |
1003 | Trade expired | The quote id has expired — re-quote and try again |
1004 | Unsupported token pair | The token pair is not supported by any provider |
1101 | Invalid fromAddress | Wallet address format is incorrect |
1102 | Invalid receiver | Receiver address format is incorrect |
1103 | Balance too low | Wallet doesn’t have enough tokens |
1104 | Insufficient gas | Wallet doesn’t have enough native token for gas |
2001 | Invalid blockchain | srcTokenBlockchain or dstTokenBlockchain is not supported |
2002 | Invalid token address | Token address format is invalid for the given blockchain |
These codes are illustrative. Always check err.reason for the exact message from the API.
Error patterns by method
Quote expired — re-quote
Quote IDs expire after a short period. If you get an expiry error onswap, re-run the quote:
Minimum amount
Network / timeout errors
Polling timeout
waitForStatus rejects with a plain Error('Polling timeout') (not a RubicApiError) when the total timeout is exceeded:
Custom HTTP client — error forwarding
If you use a custom HTTP client, you are responsible for parsing API errors. UseRubicApiError.fromApiResponse to convert the raw response body: