API ReferenceCoreError Handling

Error Handling

Error Types

All API errors follow a consistent structure that includes an error code, message, and additional details when available.

{
  "code": "invalid_request",
  "message": "The provided currency is not supported",
  "details": {
    "field": "currency_code",
    "value": "GBP",
    "allowed_values": ["XOF", "USD", "EUR"]
  }
}

Error Categories

Authentication Errors (401)

CodeDescriptionResolution
invalid_api_keyInvalid API key providedCheck your API key is correct and active
expired_api_keyAPI key has expiredGenerate a new API key in the dashboard
missing_api_keyNo API key providedInclude X-API-KEY header in your request

Authorization Errors (403)

CodeDescriptionResolution
insufficient_permissionsAPI key lacks required permissionsRequest additional permissions or use a different key
account_inactiveMerchant account is inactiveContact support to reactivate your account
rate_limit_exceededToo many requestsImplement exponential backoff in your integration

Validation Errors (400)

CodeDescriptionResolution
invalid_amountInvalid transaction amountEnsure amount is positive and within limits
invalid_currencyUnsupported currency codeUse one of: XOF, USD, EUR
invalid_phoneInvalid phone number formatUse international format: +221XXXXXXXXX
missing_required_fieldRequired field not providedCheck the API reference for required fields

Resource Errors (404)

CodeDescriptionResolution
merchant_not_foundMerchant ID doesn’t existVerify the merchant_id is correct
transaction_not_foundTransaction not foundCheck the transaction_id
customer_not_foundCustomer doesn’t existVerify the customer_id

Provider Errors (503)

CodeDescriptionResolution
provider_unavailablePayment provider is offlineRetry the request or try a different provider
provider_timeoutProvider request timed outRetry with exponential backoff
provider_rejectedProvider rejected transactionCheck provider-specific error details

Error Handling Best Practices

Implement Retry Logic

import { LomiClient, ProviderError } from '@lomi/sdk';
 
async function processPayment(data) {
  const maxRetries = 3;
  let attempt = 0;
 
  while (attempt < maxRetries) {
    try {
      const result = await lomi.transactions.create(data);
      return result;
    } catch (error) {
      if (error instanceof ProviderError && error.isRetryable()) {
        attempt++;
        await sleep(Math.pow(2, attempt) * 1000); // Exponential backoff
        continue;
      }
      throw error;
    }
  }
}

Handle Rate Limits

import { RateLimitError } from '@lomi/sdk';
 
try {
  await lomi.transactions.list();
} catch (error) {
  if (error instanceof RateLimitError) {
    const resetTime = error.resetAt;
    const waitMs = resetTime - Date.now();
    await sleep(waitMs);
    // Retry request
  }
}

Validate Input Data

import { ValidationError } from '@lomi/sdk';
 
try {
  await lomi.customers.create({
    email: 'invalid-email',
    phone: 'invalid-phone'
  });
} catch (error) {
  if (error instanceof ValidationError) {
    console.log(error.details); // Shows specific validation failures
    // Handle each validation error
  }
}

Provider-Specific Errors

Each payment provider may return specific error codes. Here’s how to handle them:

Orange Money

try {
  await lomi.transactions.create({
    provider_code: 'ORANGE',
    // ...
  });
} catch (error) {
  if (error.provider_code === 'ORANGE') {
    switch (error.provider_error_code) {
      case 'INSUFFICIENT_BALANCE':
        // Handle insufficient balance
        break;
      case 'INVALID_PIN':
        // Handle invalid PIN
        break;
      // Handle other Orange-specific errors
    }
  }
}

Wave

try {
  await lomi.transactions.create({
    provider_code: 'WAVE',
    // ...
  });
} catch (error) {
  if (error.provider_code === 'WAVE') {
    switch (error.provider_error_code) {
      case 'USER_CANCELLED':
        // Handle user cancellation
        break;
      case 'DAILY_LIMIT_EXCEEDED':
        // Handle limit exceeded
        break;
      // Handle other Wave-specific errors
    }
  }
}

Error Monitoring

We recommend using our dashboard’s error monitoring tools to:

  • Track error rates and patterns
  • Set up alerts for critical errors
  • Analyze error distributions by provider
  • Monitor API health and performance

Debugging Tools

Test Mode

Use test mode to simulate various error scenarios:

const lomi = new LomiClient({
  apiKey: 'test_key',
  debug: true // Enables detailed error logging
});

Request IDs

All API responses include a unique request ID. Include this when contacting support:

try {
  await lomi.transactions.create(data);
} catch (error) {
  console.log(error.requestId); // Use this ID for support
}