Skip to main content

Error Handling

The SDK provides typed errors with full access to the API response.

Error hierarchy

SendLimeError          (base class)
โ”œโ”€โ”€ SendLimeApiError (HTTP 4xx/5xx)
โ””โ”€โ”€ SendLimeNetworkError (connection failures)

SendLimeApiError

Thrown when the API returns a non-2xx status code.

PropertyTypeDescription
statusnumberHTTP status code (e.g. 402, 422, 429).
messagestringError message from the API.
bodyobjectFull response body.
detailsobjectValidation errors (on 422).
retryAfternumberSeconds to wait before retrying (on 429).

SendLimeNetworkError

Thrown when the fetch call itself fails (DNS, timeout, etc.).

PropertyTypeDescription
causeErrorThe original fetch error.

Example

import { SendLimeApiError, SendLimeNetworkError } from "@sendlime/node";

try {
await sendlime.messages.send({ to: "+880...", message: "Hi" });
} catch (err) {
if (err instanceof SendLimeApiError) {
console.error(err.status); // 402
console.error(err.message); // "Insufficient balance"
console.error(err.body); // { error, required, available }
console.error(err.details); // validation errors (422)
console.error(err.retryAfter); // seconds to wait (429)
}

if (err instanceof SendLimeNetworkError) {
console.error("Connection failed:", err.cause);
}
}