@lokalise/node-api
Version:
Official Lokalise API 2.0 Node.js client
44 lines (32 loc) • 1.52 kB
Markdown
To handle request errors, you can use the following approach:
```js
lokaliseApi.projects().list().catch(
(e) => {
console.log(e);
}
);
```
Or with async/await:
```js
import { ApiError } from "@lokalise/node-api";
try {
await lokaliseApi.projects().list();
} catch (e) {
console.error(e);
if (error instanceof ApiError) {
console.log(e.message); // "Request timed out after 1000ms"
console.log(e.code); // 408
console.log(e.details); // { reason: "timeout" }
}
}
```
[](https://developers.lokalise.com/reference/api-errors) are listed in the API docs.
[](https://app.lokalise.com/api2docs/curl/#resource-rate-limits) to 6 requests per second from 14 September, 2021. This limit is applied per API token and per IP address. If you exceed the limit, a 429 HTTP status code will be returned and the corresponding exception will be raised that you should handle properly. To handle such errors, we recommend an exponential backoff mechanism with a limited number of retries.
Certain responses might be marked as too big by Lokalise API. This SDK adds a `responseTooBig` boolean parameter to all paginated responses and file download responses. When the response contains the `x-response-too-big` header, this attribute returns `true`:
```js
const response = await lokaliseApi.files().download(projectId, params);
response.responseTooBig;
```