Skip to main content

Errors

ClassWhen
LibreTranslateApiErrorA non-2xx response
LibreTranslateConfigErrorInvalid configuration: a missing or malformed URL
LibreTranslateTimeoutErrorNo response within timeoutMs

LibreTranslateApiError carries status, method, path (without the query string) and the response body. LibreTranslate answers errors as { "error": "<message>" }, and that message is the error's.

StatusUsually
400A missing or invalid parameter, an unsupported file, or a key is required
403The API key is invalid, or the client is banned
429Too many requests: wait and retry
500The translation failed on the instance
import { LibreTranslateApiError } from "@hoyasumii/libretranslate";

try {
await lt.translate({ q: "Olá", target: "en" });
} catch (error) {
if (error instanceof LibreTranslateApiError && error.status === 429) {
// back off and retry
} else throw error;
}

The API key never shows​

Every error's message and body go through redact: the values of keys such as api_key become ***, and so does any literal occurrence of the client's own key, inside strings too. redact is exported for your own logs:

import { redact } from "@hoyasumii/libretranslate";

console.log(redact(payload, [process.env.LIBRETRANSLATE_API_KEY!]));