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
Code | Description |
---|---|
200 - OK | Everything worked as expected. |
201 - Created | A new resource was successfully created. |
400 - Bad Request | The request was unacceptable, often due to missing a required parameter. |
401 - Unauthorized | No valid API key provided. |
403 - Forbidden | The API key doesn't have permissions to perform the request. |
404 - Not Found | The requested resource doesn't exist. |
409 - Conflict | The request conflicts with another request (same idempotent key). |
429 - Too Many Requests | Too many requests hit the API too quickly. We recommend an exponential backoff of your requests. |
500, 502, 503, 504 - Server Errors | Something 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 Code | Description |
---|---|
api_key_invalid | The API key provided is invalid. |
api_key_expired | The API key provided has expired. |
invalid_request | The request was invalid. Check the error message for details. |
resource_not_found | The resource you're trying to access doesn't exist. |
account_invalid | The account information provided is invalid. |
bank_not_supported | The bank you're trying to connect to is not supported. |
rate_limit_exceeded | You've exceeded the rate limit for API requests. |
internal_error | An 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); }