Errors

Understand Lemu API error codes and how to handle them

The Lemu 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), and codes in the 5xx range indicate an error with the Lemu servers.

HTTP Status Codes

CodeDescription
200 - OKEverything worked as expected.
201 - CreatedA new resource was successfully created.
400 - Bad RequestThe request was unacceptable, often due to missing a required parameter.
401 - UnauthorizedNo valid API key provided.
403 - ForbiddenThe API key doesn't have permissions to perform the request.
404 - Not FoundThe requested resource doesn't exist.
409 - ConflictThe request conflicts with another request (same idempotent key).
429 - Too Many RequestsToo many requests hit the API too quickly. We recommend an exponential backoff of your requests.
500, 502, 503, 504 - Server ErrorsSomething went wrong on Lemu's end.

Error Response Format

All errors follow a similar response format. Here's an example:

Error Response Example
{
  "status": "error",
  "code": "invalid_request",
  "message": "The account number provided is invalid",
  "errors": [
    {
      "field": "account_number",
      "message": "Account number must be 10 digits"
    }
  ],
  "request_id": "req_1a2b3c4d5e6f"
}

Common Error Codes

Error CodeDescription
api_key_invalidThe API key provided is invalid.
api_key_expiredThe API key provided has expired.
invalid_requestThe request was invalid. Check the error message for details.
resource_not_foundThe resource you're trying to access doesn't exist.
account_invalidThe account information provided is invalid.
bank_not_supportedThe bank you're trying to connect to is not supported.
rate_limit_exceededYou've exceeded the rate limit for API requests.
internal_errorAn internal error occurred on our servers.

Handling Errors

We recommend writing code that gracefully handles all possible API errors. Here's an example of how to handle errors in JavaScript:

JavaScript Error Handling
try {
  const response = await fetch('https://api.lemu.com/v1/banks/verify', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': 'YOUR_API_KEY',
      'X-API-Secret': 'YOUR_API_SECRET'
    },
    body: JSON.stringify({
      account_number: '0123456789',
      bank_code: 'SOME_BANK'
    })
  });
  
  const data = await response.json();
  
  if (response.ok) {
    // Handle success
    console.log(data);
  } else {
    // Handle error
    console.error('Error:', data.message);
    
    // Check for specific error types
    if (data.code === 'account_invalid') {
      // Handle invalid account
    } else if (data.code === 'bank_not_supported') {
      // Handle unsupported bank
    }
    
    // Log request ID for support
    console.error('Request ID:', data.request_id);
  }
} catch (error) {
  // Handle network or other errors
  console.error('Network error:', error);
}