Reference

Error Handling

CamelPay returns consistent error responses with HTTP status codes and machine-readable error details.

HTTP Status Codes

CodeMeaningAction
200SuccessProcess response
201CreatedResource created
400Bad RequestCheck request body and parameters
401UnauthorizedVerify API key or JWT token
402Payment RequiredInsufficient wallet balance
404Not FoundResource doesn't exist
409ConflictDuplicate idempotency key or resource
422Unprocessable EntityValidation failed — check errors array
429Too Many RequestsRate limit exceeded — implement backoff
500Server ErrorRetry with exponential backoff

Error Response Format

json
{
  "success": false,
  "data": null,
  "message": "Validation failed",
  "errors": [
    {
      "field": "phone_number",
      "message": "invalid format"
    }
  ]
}

Retry Strategy

For 5xx errors and network failures, use exponential backoff:

async function retryWithBackoff(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      if (error.status >= 500 || !error.status) {
        await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
      } else {
        throw error; // Don't retry client errors
      }
    }
  }
}

Error Code Reference

CodeFieldMessageFix
400slugpayment page not foundVerify slug exists
400amountmust be >= 500Increase amount
401missing X-API-Key headerAdd API key header
401invalid or expired API KeyCheck key validity
402insufficient wallet balanceTop up wallet
409duplicate idempotency keyUse new key
422phone_numberinvalid formatUse E.164 format
429rate limit exceededImplement backoff