Error Handling

Overview

DEXCHANGE-API uses conventional HTTP response codes to indicate the success or failure of API requests. In general:

  • Codes in the 2xx range indicate success
  • Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted)
  • Codes in the 5xx range indicate an error with our servers

Error Response Format

All error responses follow this format:

{
  "success": false,
  "message": "Error description",
  "code": "ERROR_CODE"
}

HTTP Status Codes

CodeDescription
200Success - The request was successful
400Bad Request - The request was invalid
401Unauthorized - Invalid API key
403Forbidden - You don’t have permission
404Not Found - The requested resource doesn’t exist
429Too Many Requests - Rate limit exceeded
500Server Error - Something went wrong on our end

Common Error Codes

Authentication Errors

CodeDescription
INVALID_API_KEYThe provided API key is invalid
EXPIRED_API_KEYThe API key has expired
MISSING_API_KEYNo API key was provided

Transaction Errors

CodeDescription
INSUFFICIENT_FUNDSThe user doesn’t have enough balance
INVALID_AMOUNTThe transaction amount is invalid
TRANSACTION_FAILEDThe transaction could not be processed
DUPLICATE_TRANSACTIONA transaction with this reference already exists

Validation Errors

CodeDescription
INVALID_PHONEThe phone number format is invalid
INVALID_CURRENCYThe currency is not supported
MISSING_REQUIRED_FIELDA required field is missing

Service Errors

CodeDescription
SERVICE_UNAVAILABLEThe requested service is currently unavailable
OPERATOR_ERRORThe mobile operator returned an error
TIMEOUT_ERRORThe request timed out

Best Practices

  1. Always check the response status

    • Verify both HTTP status code and response body
  2. Implement proper error handling

    • Handle both expected and unexpected errors
    • Log errors for debugging
  3. Retry mechanism

    • Implement exponential backoff for 5xx errors
    • Don’t retry on 4xx errors (except 429)
  4. Rate limiting

    • Monitor rate limit headers
    • Implement rate limit handling

Example Error Handling

try {
  const response = await dexchangeApi.initiatePayment({
    amount: 1000,
    phone: '221700000000',
  });
} catch (error) {
  if (error.code === 'INVALID_PHONE') {
    // Handle invalid phone number
  } else if (error.code === 'INSUFFICIENT_FUNDS') {
    // Handle insufficient funds
  } else {
    // Handle other errors
  }
}

Support

If you encounter any errors that you can’t resolve, please contact our support team:

Error Handling

Overview

DEXCHANGE-API uses conventional HTTP response codes to indicate the success or failure of API requests. In general:

  • Codes in the 2xx range indicate success
  • Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted)
  • Codes in the 5xx range indicate an error with our servers

Error Response Format

All error responses follow this format:

{
  "success": false,
  "message": "Error description",
  "code": "ERROR_CODE"
}

HTTP Status Codes

CodeDescription
200Success - The request was successful
400Bad Request - The request was invalid
401Unauthorized - Invalid API key
403Forbidden - You don’t have permission
404Not Found - The requested resource doesn’t exist
429Too Many Requests - Rate limit exceeded
500Server Error - Something went wrong on our end

Common Error Codes

Authentication Errors

CodeDescription
INVALID_API_KEYThe provided API key is invalid
EXPIRED_API_KEYThe API key has expired
MISSING_API_KEYNo API key was provided

Transaction Errors

CodeDescription
INSUFFICIENT_FUNDSThe user doesn’t have enough balance
INVALID_AMOUNTThe transaction amount is invalid
TRANSACTION_FAILEDThe transaction could not be processed
DUPLICATE_TRANSACTIONA transaction with this reference already exists

Validation Errors

CodeDescription
INVALID_PHONEThe phone number format is invalid
INVALID_CURRENCYThe currency is not supported
MISSING_REQUIRED_FIELDA required field is missing

Service Errors

CodeDescription
SERVICE_UNAVAILABLEThe requested service is currently unavailable
OPERATOR_ERRORThe mobile operator returned an error
TIMEOUT_ERRORThe request timed out

Best Practices

  1. Always check the response status

    • Verify both HTTP status code and response body
  2. Implement proper error handling

    • Handle both expected and unexpected errors
    • Log errors for debugging
  3. Retry mechanism

    • Implement exponential backoff for 5xx errors
    • Don’t retry on 4xx errors (except 429)
  4. Rate limiting

    • Monitor rate limit headers
    • Implement rate limit handling

Example Error Handling

try {
  const response = await dexchangeApi.initiatePayment({
    amount: 1000,
    phone: '221700000000',
  });
} catch (error) {
  if (error.code === 'INVALID_PHONE') {
    // Handle invalid phone number
  } else if (error.code === 'INSUFFICIENT_FUNDS') {
    // Handle insufficient funds
  } else {
    // Handle other errors
  }
}

Support

If you encounter any errors that you can’t resolve, please contact our support team: