Errors and retries
How the Faurya Billing SDK reports failures, which ones it retries for you, and how to handle the rest.
Errors and retries
Every error the SDK throws extends FauryaError, so one instanceof check catches them all. Errors that came back from the Faurya API are a FauryaApiError, with a more specific class for each kind of problem.
Handling an error
import {
FauryaApiError,
FauryaConflictError,
FauryaUnprocessableError,
} from "@faurya/billing";
try {
await faurya.billing.invoices.upsert("inv_1042", invoice);
} catch (error) {
if (error instanceof FauryaConflictError && error.code === "INVOICE_LOCKED") {
// The invoice was already paid, so it can't change.
// Void it and send a corrected invoice with a new id.
} else if (error instanceof FauryaUnprocessableError && error.code === "CUSTOMER_NOT_FOUND") {
// Send the customer first, then retry the invoice.
} else if (error instanceof FauryaApiError) {
console.error(error.code, error.errors, error.requestId);
}
throw error;
}Every FauryaApiError carries:
| Property | What it is |
|---|---|
status | The HTTP status, e.g. 409 |
code | A stable code to branch on, e.g. INVOICE_LOCKED |
message | A human-readable explanation |
errors | Every field problem at once: { field, code, message }[] |
requestId | Quote this to Faurya support — it links your logs to ours |
Fix every field in one go
A validation failure lists every problem in the request, each with the exact path to the field, so you can fix them all at once:
catch (error) {
if (error instanceof FauryaValidationError) {
for (const e of error.errors) {
console.log(`${e.field}: ${e.message}`);
// line_items[2].amount: USD amounts have at most 2 decimal places
}
}
}Error classes
| Class | When you'll see it | What to do |
|---|---|---|
FauryaValidationError | 400 — a field is invalid or missing, or a payment id was already used (DUPLICATE_TRANSACTION) | Fix the fields in errors |
FauryaAuthenticationError | 401 — the API key is wrong or missing | Check FAURYA_API_KEY |
FauryaNotFoundError | 404 — the object you asked for doesn't exist | Check the id |
FauryaConflictError | 409 — the change isn't allowed on what's already stored | See the codes below |
FauryaPayloadTooLargeError | 413 — the request is over the size limit | Send fewer lines or items per call |
FauryaUnprocessableError | 422 — it refers to something Faurya doesn't have yet | Send that object first |
FauryaRateLimitError | 429 — too many requests | Retried automatically; for backlogs use bulk import |
FauryaServerError | 5xx — a problem on Faurya's side; nothing was saved | Retried automatically when safe |
FauryaInputError | Caught by the SDK before sending, e.g. an invalid id | Fix the call |
FauryaConfigError | Missing key, invalid option, or running in a browser | Fix your setup |
FauryaTimeoutError | The request took longer than timeoutMs | Retry, or raise the timeout |
FauryaConnectionError | Faurya couldn't be reached | Check the network; retry |
FauryaAbortError | You cancelled the request with an AbortSignal | — |
Codes you'll most likely meet
| Code | Meaning | Fix |
|---|---|---|
CUSTOMER_NOT_FOUND | The invoice names a customer Faurya doesn't have | Upsert the customer first |
PLAN_NOT_FOUND | A line names an unknown plan | Upsert the plan first |
INVOICE_NOT_FOUND | The transaction names an unknown invoice | Upsert the invoice first |
INVOICE_LOCKED | The invoice has a payment, refund or void, so it's frozen | Void it and send a new invoice |
TRANSACTION_IMMUTABLE | You tried to change a transaction's amount or type | Record a refund or reversal instead |
EVENT_IMMUTABLE | You re-sent an event id with a different body | Retract it and send a new event |
PLAN_CADENCE_LOCKED | You changed the interval of a plan already in use | Create a new plan |
AMOUNT_EXCEEDS_INVOICE | Payments would exceed the invoice total | Check the amount |
AMOUNT_EXCEEDS_PAYMENT | A refund exceeds the payment it refunds | Check the amount |
DUPLICATE_TRANSACTION | payments.create with an id already recorded | It's already in Faurya — safe to ignore |
The full list is in the Billing API errors reference.
What the SDK retries for you
You don't need to write retry loops. By default the SDK retries up to 2 times, waiting a little longer each time (starting at 0.5 s, capped at 8 s):
- Rate limits (429) are retried for every call, waiting as long as Faurya asks (up to 60 s).
- Timeouts, network errors and server errors are retried for every
billing.*call and import call, because those are safe to repeat — sending the same object twice changes nothing. payments.create,payments.deleteandgoals.createare never retried after a timeout or server error. The request may have landed, and retrying could record a payment twice. If you retry one yourself, theDUPLICATE_TRANSACTIONcheck protects you.
Errors like 400, 409 and 422 are never retried — sending the same request again would fail the same way.
Change the retry count for the whole client, or for one call:
const faurya = createFauryaBilling({ maxRetries: 5 });
await faurya.billing.customers.upsert("cus_42", data, { maxRetries: 0 });Timeouts and cancelling
Each request times out after 30 seconds by default. Override it per client or per call, or cancel with an AbortSignal:
// Slower network? Give it more time.
await faurya.billing.invoices.upsert("inv_1042", invoice, { timeoutMs: 60_000 });
// Cancel if the user leaves
const controller = new AbortController();
const pending = faurya.billing.subscriptions.retrieve("sub_900", { signal: controller.signal });
controller.abort(); // throws FauryaAbortErrorLog the request id
Always log requestId with failures. It's the one value Faurya support needs to find your request:
catch (error) {
if (error instanceof FauryaApiError) {
logger.error({ code: error.code, status: error.status, requestId: error.requestId });
}
}Successful responses carry it too, as request_id.
Warnings are not errors
A successful response can include warnings. They never mean the save failed — just that something is worth knowing:
| Warning | Meaning |
|---|---|
VISITOR_PENDING | The visitor hasn't been processed yet. The link completes on its own. |
VISITOR_ALREADY_LINKED | That visitor already belongs to another customer, so the link wasn't moved. The object was still saved. |
IGNORED_FIELD | A compatibility field Faurya accepts but doesn't store. |
const res = await faurya.billing.customers.upsert("cus_42", { faurya_visitor_id: visitorId });
for (const w of res.warnings) console.warn(w.code, w.message);