Skip to main content

Error Handling

The API uses standard HTTP status codes and returns detailed error information in the response body.

HTTP Status Codes

CodeDescription
200Success
201Created
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
403Forbidden - Insufficient permissions
404Not Found - Resource doesn’t exist
409Conflict - Duplicate idempotency key with different payload
422Unprocessable Entity - Validation failed
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Error Response Format

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error message",
    "details": [
      {
        "field": "fieldName",
        "message": "Field-specific error"
      }
    ],
    "requestId": "req_abc123"
  }
}

Common Error Codes

Validation Errors

CodeDescription
VALIDATION_ERRORRequest parameters failed validation
INVALID_CURRENCYUnsupported currency code
INVALID_AMOUNTAmount is out of allowed range
INVALID_WALLET_ADDRESSWallet address format is invalid
INVALID_NETWORKUnsupported network
INVALID_GATEWAYGateway ID not found or not enabled

Resource Errors

CodeDescription
TRANSACTION_NOT_FOUNDTransaction ID doesn’t exist
PROJECT_NOT_FOUNDProject ID doesn’t exist
GATEWAY_UNAVAILABLESelected gateway is currently unavailable

Rate Limiting

CodeDescription
RATE_LIMIT_EXCEEDEDToo many requests — include a pk_ key for higher limits

Authentication Errors

CodeDescription
INVALID_API_KEYThe API key is invalid or revoked

Handling Errors

JavaScript Example

async function getQuotes(params) {
  const response = await fetch(
    `https://api.nowramp.com/public/v1/onramp/quotes?${new URLSearchParams(params)}`
  );

  const data = await response.json();

  if (!data.success) {
    switch (data.error.code) {
      case 'VALIDATION_ERROR':
        // Show field-specific errors to the user
        console.error('Validation:', data.error.details);
        break;
      case 'INVALID_AMOUNT':
        // Amount is below minimum or above maximum
        console.error('Invalid amount:', data.error.message);
        break;
      case 'RATE_LIMIT_EXCEEDED':
        // Back off and retry
        await new Promise(r => setTimeout(r, 5000));
        return getQuotes(params);
      default:
        throw new Error(data.error.message);
    }
  }

  return data.data;
}

Retry Strategy

For transient errors (5xx, network issues), implement exponential backoff:
async function fetchWithRetry(url, options, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(url, options);

      if (response.status >= 500) {
        throw new Error('Server error');
      }

      return response;
    } catch (error) {
      if (i === maxRetries - 1) throw error;

      const delay = Math.pow(2, i) * 1000; // 1s, 2s, 4s
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
}
Always include the requestId from error responses when contacting support.