The Lymo API returns standard HTTP status codes for every response. When a request fails, the response body always includes a JSON object with two fields: error (an integer status code) and message (a human-readable description of what went wrong).
Every error response follows this structure:
{
"error": 400,
"message": "Invalid request: name is required"
}
Read the message field to understand what caused the failure and what you need to fix.
Common error codes
| Code | Status | Description | What to do |
|---|
| 400 | Bad Request | Invalid or missing parameters | Check your request body and query params |
| 401 | Unauthorized | Invalid or missing API key | Verify your Authorization header |
| 403 | Forbidden | Insufficient permissions | Check your API key permissions |
| 404 | Not Found | Resource doesn’t exist | Verify the resource ID |
| 429 | Too Many Requests | Rate limit exceeded | Retry after the specified delay |
| 500 | Internal Server Error | Server-side issue | Retry with exponential backoff |
Handling errors in code
Check the status code and parse the error body in your error handler:
async function createPlant(name, tag) {
const response = await fetch("https://api.lymo.jp/plants", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({ name, tag }),
});
if (!response.ok) {
const error = await response.json();
throw new Error(`API error ${error.error}: ${error.message}`);
}
return response.json();
}
try {
const plant = await createPlant("monstera", "tropical");
console.log(plant);
} catch (err) {
console.error(err.message);
}
Retrying failed requests
Retry 5xx errors using exponential backoff — wait longer between each attempt to avoid overwhelming the server. Do not retry 4xx errors without first fixing the request; the same broken request will always produce the same failure.
Here is a simple backoff strategy in pseudocode:
max_retries = 3
delay = 1 second
for attempt in 1..max_retries:
response = send_request()
if response.status >= 500:
wait(delay)
delay = delay * 2 # double the delay each attempt
else:
break
Never retry a 400 Bad Request without first fixing the request — it will always fail.