Skip to main content

Error Handling

All errors return JSON with consistent structure and appropriate HTTP status codes.

Error Response Format

{
  "error": {
    "code": "INSUFFICIENT_BALANCE",
    "message": "Insufficient balance for transaction",
    "details": {
      "required": "1.5 SOL",
      "available": "1.2 SOL"
    }
  }
}

HTTP Status Codes

CodeDescription
200Success
400Bad Request - Invalid parameters
401Unauthorized - Invalid API key
404Not Found - Resource doesn’t exist
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Common Error Codes

Quote Errors

CodeDescription
INVALID_ASSETUnsupported asset symbol
AMOUNT_TOO_SMALLBelow minimum amount
INSUFFICIENT_LIQUIDITYNot enough liquidity

Transaction Errors

CodeDescription
INVALID_QUOTEQuote expired or not found
INVALID_SIGNATUREMalformed signed transaction
INSUFFICIENT_BALANCENot enough tokens
ROUTING_UNAVAILABLEPrivate mode unavailable

Authentication Errors

CodeDescription
INVALID_API_KEYAPI key is invalid
EXPIRED_API_KEYAPI key has expired
RATE_LIMIT_EXCEEDEDToo many requests

Retry Logic

Implement exponential backoff for retries:
async function retryRequest(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise(r => setTimeout(r, 1000 * Math.pow(2, i)));
    }
  }
}