NEXO
Launch App
Back to Docs
Advanced5 min read

Error Handling

Handling errors and exceptions in NEXO

Error Types

NEXO uses structured error responses for easy handling.

Error Response Format

json
{
  "error": {
    "code": "INSUFFICIENT_FUNDS",
    "message": "Not enough SOL for transaction",
    "details": {
      "required": 1.5,
      "available": 0.5
    }
  }
}

Common Error Codes

  • INVALID_PARAMS - Invalid request parameters
  • UNAUTHORIZED - Invalid or missing API key
  • RATE_LIMITED - Too many requests
  • INSUFFICIENT_FUNDS - Not enough balance
  • SLIPPAGE_EXCEEDED - Price moved beyond tolerance
  • TX_FAILED - Transaction execution failed
  • RISK_BLOCKED - Transaction blocked due to risk

SDK Error Handling

typescript
import { NexoError, ErrorCodes } from '@nexo/sdk';

try {
  const result = await client.swap(params);
} catch (error) {
  if (error instanceof NexoError) {
    switch (error.code) {
      case ErrorCodes.SLIPPAGE_EXCEEDED:
        // Increase slippage or retry
        break;
      case ErrorCodes.INSUFFICIENT_FUNDS:
        // Notify user to add funds
        break;
      default:
        // Handle other errors
    }
  }
}

Retry Logic

typescript
const result = await client.executeWithRetry(tx, {
  maxRetries: 3,
  backoff: 'exponential',
  retryableErrors: ['TX_FAILED', 'TIMEOUT']
});