Skip to main content
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).

Error response format

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

CodeStatusDescriptionWhat to do
400Bad RequestInvalid or missing parametersCheck your request body and query params
401UnauthorizedInvalid or missing API keyVerify your Authorization header
403ForbiddenInsufficient permissionsCheck your API key permissions
404Not FoundResource doesn’t existVerify the resource ID
429Too Many RequestsRate limit exceededRetry after the specified delay
500Internal Server ErrorServer-side issueRetry 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.