Skip to Content

Error Handling

The SDK provides typed error classes for every failure scenario.

Error classes

import { EInvoiceError, EInvoiceApiError, EInvoiceRateLimitError, EInvoiceTimeoutError, EInvoiceConfigError, EInvoiceWebhookError, } from '@useyona/einvoice-js';
ClassThrown when
EInvoiceErrorBase class for all SDK errors
EInvoiceApiErrorHTTP 4xx/5xx response from the API
EInvoiceRateLimitErrorHTTP 429 — too many requests
EInvoiceTimeoutErrorRequest exceeds configured timeout
EInvoiceConfigErrorSDK misconfiguration (e.g. missing organizationId)
EInvoiceWebhookErrorWebhook signature verification failed

EInvoiceApiError

Thrown for any HTTP 4xx or 5xx response.

PropertyTypeDescription
statusCodenumberHTTP status code
errorCodestringMachine code (e.g. 'VAL001')
messagestringHuman-readable message
errorsArray<{ field?: string; message: string }>Field-level errors
try { await client.invoices.create({ /* ... */ }); } catch (err) { if (err instanceof EInvoiceApiError) { handleValidationError(err.statusCode, err.errorCode, err.errors); } }
Available properties on EInvoiceApiError

err.statusCode — the HTTP status (e.g. 400). err.errorCode — a machine-readable code (e.g. 'VAL001'). err.errors — an array of field-level errors with field and message.

EInvoiceRateLimitError

Thrown when the API returns HTTP 429. Extends EInvoiceApiError.

PropertyTypeDescription
retryAfternumberSeconds to wait before retrying
if (err instanceof EInvoiceRateLimitError) { console.log(`Rate limited. Retry after ${err.retryAfter}s`); await sleep(err.retryAfter * 1000); // retry the request }

EInvoiceTimeoutError

Thrown when a request exceeds the configured timeout.

if (err instanceof EInvoiceTimeoutError) { logTimeout(err.timeoutMs); }
timeoutMs

err.timeoutMs contains the timeout value (in milliseconds) that was exceeded.

EInvoiceConfigError

Thrown for SDK misconfiguration — e.g. calling client.webhooks.create() without organizationId.

EInvoiceWebhookError

Thrown when webhook signature verification fails in verifyWebhook().

Automatic retries

The SDK automatically retries certain errors:

Error typeRetried?Behavior
5xx errorsYesUp to maxAttempts with exponential backoff + jitter
429 errorsYesRespects Retry-After header, then retries
4xx errorsNeverThese are client errors — fix the request

Error codes reference

CodeMeaningHTTP Status
AUTH001Invalid credentials401
AUTH002Token expired401
AUTH004Unauthorized401
AUTH005Forbidden403
VAL001Validation failed400
VAL002Missing required field400
RES001Not found404
RES002Already exists409
BIZ001Insufficient balance400
BIZ004Invalid state400
INV001Invalid invoice format400
INV002Already submitted400
INV003Cannot modify400
SYS001Internal error500
TAX001Tax authority connection error502
Last updated on