Skip to main content
The Leonar API uses standard HTTP status codes and returns structured error responses.

Error format

{
  "error": {
    "code": "validation_error",
    "message": "email: Invalid email format"
  }
}

Error codes

CodeHTTP statusDescription
validation_error400Invalid request data
invalid_api_key401Missing or invalid API key
insufficient_scope403API key lacks the required scope
not_found404Resource not found
rate_limit_exceeded429Too many requests
internal_error500Server error

Handling errors

const response = await fetch(`${BASE_URL}/contacts`, {
  headers: { Authorization: `Bearer ${apiKey}` },
});

if (!response.ok) {
  const { error } = await response.json();

  switch (error.code) {
    case "invalid_api_key":
      throw new Error("Check your API key");
    case "rate_limit_exceeded":
      // Wait and retry
      break;
    case "validation_error":
      console.error("Validation:", error.message);
      break;
    default:
      throw new Error(error.message);
  }
}

const { data } = await response.json();