Skip to main content

HTTP Status Codes

CodeStatusDescription
200OKRequest successful
201CreatedResource created successfully
400Bad RequestInvalid request parameters
401UnauthorizedInvalid or missing authentication
403ForbiddenInsufficient permissions
404Not FoundResource not found
409ConflictResource conflict (e.g., duplicate order)
422Unprocessable EntityValid request but business logic error
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error
502Bad GatewayExchange adapter error
503Service UnavailableService temporarily unavailable

Error Response Format

All errors follow a consistent JSON format:
{
  "error": {
    "code": 400,
    "type": "INVALID_PARAMETER",
    "message": "Invalid symbol",
    "details": "Symbol 'INVALID-PAIR' is not supported",
    "field": "symbol",
    "timestamp": 1698765432000,
    "requestId": "req_abc123456"
  }
}

Common Error Types

Authentication Errors

INVALID_API_KEY

{
  "error": {
    "code": 401,
    "type": "INVALID_API_KEY",
    "message": "Invalid API key",
    "details": "The provided API key is not valid or has been revoked"
  }
}

INVALID_SIGNATURE

{
  "error": {
    "code": 401,
    "type": "INVALID_SIGNATURE",
    "message": "Invalid signature",
    "details": "The request signature does not match the expected value"
  }
}

Trading Errors

INSUFFICIENT_BALANCE

{
  "error": {
    "code": 422,
    "type": "INSUFFICIENT_BALANCE",
    "message": "Insufficient balance",
    "details": "Available balance: 1000.00 USDC, Required: 2000.00 USDC",
    "field": "quantity"
  }
}

ORDER_NOT_FOUND

{
  "error": {
    "code": 404,
    "type": "ORDER_NOT_FOUND",
    "message": "Order not found",
    "details": "Order with ID 'ord_1234567890' does not exist or has been canceled",
    "field": "orderId"
  }
}

Smart Routing & Execution Errors

Smart order endpoints return errors with a top-level success: false payload instead of the nested error object used by legacy endpoints.

CREDENTIAL_ERROR

{
  "success": false,
  "error": "Invalid Lighter private key format. Expected 64 or 80 hex characters.",
  "code": "CREDENTIAL_ERROR",
  "timestamp": 1234567890
}

ROUTING_ERROR

{
  "success": false,
  "error": "No routing data available for DOGE. The symbol may not be supported.",
  "code": "ROUTING_ERROR",
  "timestamp": 1234567890
}

EXECUTION_ERROR

{
  "success": false,
  "error": "Order execution failed: Insufficient balance",
  "code": "EXECUTION_ERROR",
  "details": "API Error 400: Insufficient USDC balance",
  "timestamp": 1234567890
}

Rate Limiting Errors

RATE_LIMIT_EXCEEDED

{
  "error": {
    "code": 429,
    "type": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit exceeded",
    "details": "Too many requests. Limit: 60 requests per minute",
    "retryAfter": 30
  }
}

Error Handling Best Practices

1. Implement Retry Logic

async function apiCallWithRetry(apiCall, maxRetries = 3) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      return await apiCall();
    } catch (error) {
      if (error.status === 429) {
        // Rate limit - wait and retry
        const retryAfter = error.retryAfter || Math.pow(2, attempt);
        await sleep(retryAfter * 1000);
        continue;
      }
      
      if (error.status >= 500 && attempt < maxRetries) {
        // Server error - exponential backoff
        await sleep(Math.pow(2, attempt) * 1000);
        continue;
      }
      
      // Don't retry client errors (4xx)
      throw error;
    }
  }
}

2. Handle Specific Error Types

async function placeOrder(orderData) {
  try {
    const response = await dexaggClient.placeOrder(orderData);
    return response;
  } catch (error) {
    switch (error.type) {
      case 'INSUFFICIENT_BALANCE':
        showError('Insufficient balance. Please deposit more funds.');
        break;
        
      case 'MIN_ORDER_SIZE':
        const minSize = extractMinSize(error.details);
        return placeOrder({ ...orderData, quantity: minSize });
        
      case 'RATE_LIMIT_EXCEEDED':
        await sleep(error.retryAfter * 1000);
        return placeOrder(orderData);
        
      default:
        console.error('Unexpected error:', error);
        showError('An unexpected error occurred. Please try again.');
    }
  }
}

Support and Debugging

When reporting errors:
  1. Include the requestId from the error response
  2. Provide the full error response (sanitize sensitive data)
  3. Include request details (endpoint, parameters, timestamp)
  4. Describe the expected behavior
Contact support:
Always validate input parameters before making API calls to avoid unnecessary errors and rate limit consumption.