Skip to main content

Error Codes

Comprehensive guide to error codes returned by the eXlr8 API and how to handle them.

Error Response Format​

All API errors follow a consistent format:

{
"error": "Human-readable error message",
"errCode": "ERROR_CODE"
}

General Error Codes​

HTTP 400 - Bad Request​

Error CodeDescriptionCommon Causes
BAD_REQUESTThe request was invalid or malformedMissing required fields, incorrect data format, invalid JSON

Example:

{
"error": "invalid variant ID",
"errCode": "BAD_REQUEST"
}

HTTP 401 - Unauthorized​

Error CodeDescriptionCommon Causes
UNAUTHORIZEDAuthentication failedInvalid credentials, missing headers, expired tokens

Example:

{
"error": "unauthenticated",
"errCode": "UNAUTHORIZED"
}

HTTP 403 - Forbidden​

Error CodeDescriptionCommon Causes
FORBIDDENInsufficient permissionsAccessing resources outside your scope, IP restrictions

Example:

{
"error": "forbidden: param: admin user does not have access to DP: INVALID_DP_ID",
"errCode": "FORBIDDEN"
}

HTTP 404 - Not Found​

Error CodeDescriptionCommon Causes
RECORD_NOT_FOUNDRequested resource not foundInvalid IDs, deleted resources, typos in parameters

Examples:

{
"error": "Order not found",
"errCode": "RECORD_NOT_FOUND"
}
{
"error": "product not found for dpID: YOUR_DP_ID, productID: PRODUCT_ID",
"errCode": "RECORD_NOT_FOUND"
}

HTTP 409 - Conflict​

Error CodeDescriptionCommon Causes
CONFLICTRequest conflicts with current stateDuplicate external references, concurrent modifications

Example:

{
"error": "order with externalRefID already exist",
"errCode": "CONFLICT"
}

HTTP 422 - Unprocessable Entity​

Error CodeDescriptionCommon Causes
UNPROCESSABLE_ENTITYValid request but semantic errorsBusiness logic violations, invalid combinations

Example:

{
"error": "Cannot process order for inactive product",
"errCode": "UNPROCESSABLE_ENTITY"
}

HTTP 500 - Internal Server Error​

Error CodeDescriptionCommon Causes
INTERNAL_SERVER_ERRORUnexpected server errorServer issues, temporary outages, system problems

Example:

{
"error": "An unexpected error occurred",
"errCode": "INTERNAL_SERVER_ERROR"
}

Business Logic Error Codes​

Error CodeDescriptionResolution
INSUFFICIENT_BALANCENot enough wallet balanceTop up wallet or reduce order amount
OUT_OF_STOCKProduct variant unavailableChoose different variant or try later

Examples:

{
"error": "Insufficient wallet balance for this order",
"errCode": "INSUFFICIENT_BALANCE"
}
{
"error": "Product variant is out of stock",
"errCode": "OUT_OF_STOCK"
}

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) {
const errorData = await error.response?.json();

// Don't retry on client errors (4xx)
if (error.response?.status >= 400 && error.response?.status < 500) {
throw error;
}

// Retry on server errors (5xx) with exponential backoff
if (attempt < maxRetries) {
const delay = Math.pow(2, attempt) * 1000; // 2s, 4s, 8s
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}

throw error;
}
}
}

2. Specific Error Handling​

async function handleApiError(error) {
const errorData = await error.response?.json();

switch (errorData?.errCode) {
case 'INSUFFICIENT_BALANCE':
// Redirect to top-up page or show balance warning
await handleInsufficientBalance();
break;

case 'OUT_OF_STOCK':
// Show alternative products or notify when back in stock
await handleOutOfStock(errorData.productID);
break;

case 'UNAUTHORIZED':
// Refresh credentials or redirect to login
await refreshCredentials();
break;

case 'RECORD_NOT_FOUND':
// Show user-friendly "not found" message
showNotFoundMessage();
break;

case 'INTERNAL_SERVER_ERROR':
// Log error and show generic error message
logError(errorData);
showGenericErrorMessage();
break;

default:
// Handle unknown errors
logError(errorData);
showGenericErrorMessage();
}
}

3. Error Logging​

class ErrorLogger {
static logError(error, context = {}) {
const errorLog = {
timestamp: new Date().toISOString(),
errorCode: error.errCode,
errorMessage: error.error,
context: context,
userAgent: navigator.userAgent,
url: window.location.href
};

// Send to your logging service
console.error('API Error:', errorLog);

// Optional: Send to external logging service
// await sendToLoggingService(errorLog);
}
}

Error Prevention​

1. Validation Before API Calls​

function validateOrderRequest(orderData) {
const errors = [];

if (!orderData.dpID) {
errors.push('dpID is required');
}

if (!orderData.variantID || !orderData.variantID.startsWith('VAR-')) {
errors.push('Valid variantID is required');
}

if (!orderData.externalRefID || orderData.externalRefID.length < 1) {
errors.push('externalRefID is required and must be unique');
}

if (errors.length > 0) {
throw new Error(`Validation failed: ${errors.join(', ')}`);
}
}

2. Balance Verification​

async function validateSufficientBalance(orderAmount) {
const balance = await getWalletBalance();

if (balance.balance < orderAmount) {
throw new Error('Insufficient balance for this order');
}
}

Monitoring and Alerting​

Error Rate Monitoring​

class ErrorMonitor {
constructor() {
this.errorCounts = new Map();
this.totalRequests = 0;
}

recordError(errCode) {
this.errorCounts.set(errCode, (this.errorCounts.get(errCode) || 0) + 1);
}

recordRequest() {
this.totalRequests++;
}

getErrorRate() {
const totalErrors = Array.from(this.errorCounts.values()).reduce((a, b) => a + b, 0);
return this.totalRequests > 0 ? (totalErrors / this.totalRequests) * 100 : 0;
}

getErrorBreakdown() {
return Object.fromEntries(this.errorCounts);
}
}

Common Solutions​

Error ScenarioSolution
Authentication failsVerify credentials, check header format
Orders not foundVerify dpID and orderID/externalRefID
Products not availableCheck product catalog, verify variant IDs
Insufficient balanceTop up wallet or reduce order amount
Rate limitingImplement exponential backoff and request queuing

Contact Support​

If you encounter persistent errors or need assistance:

  • Include: Error codes, request details, and timestamps
  • Response Time: Typically within 24 hours for technical issues