Pular para o conteúdo

Error handling

Every failed call raises a typed exception. The class tells you the category; each instance carries the HTTP statusCode, a message, and the raw response body (rawBody) for logging. Catch the specific type you can recover from, and fall back to the base type for everything else.

Exception hierarchy

The semantics are identical across languages; only the names differ. Node uses *Error, Java and .NET use *Exception, and Swift collapses them into a single LinaAPIError with a kind enum.

HTTPMeaningNodeJava / .NETSwift kind
Base type (all failures)LinaApiErrorLinaApiException
400Invalid input / validationBadRequestErrorBadRequestException.badRequest
401Missing or invalid tokenUnauthorizedErrorUnauthorizedException.unauthorized
403Role/tenant not allowedForbiddenErrorForbiddenException.forbidden
404Resource not foundNotFoundErrorNotFoundException.notFound
422 / 424Account holder (RP) failureDependencyErrorDependencyException.dependency
429Rate limit exceededRateLimitErrorRateLimitException.rateLimited
5xxUnexpected backend errorServerErrorServerException.server
Timeout / connection failureNetworkErrorNetworkException.network

Catching errors

import {
LinaApiError, DependencyError, UnauthorizedError, RateLimitError,
} from '@linainfratech/embedded-payments';

try {
await client.payments.processJsr(req, { clientIp });
} catch (e) {
if (e instanceof DependencyError) {
  // 424 — account holder failed; ask the payer to try again later
} else if (e instanceof RateLimitError) {
  // 429 — back off; e.retryAfterMs (if present) tells you how long
} else if (e instanceof UnauthorizedError) {
  // 401 — check client credentials / roles
} else if (e instanceof LinaApiError) {
  // e.rawBody may contain the payer's CPF and creditor account details —
  // treat it as PII: don't log/persist it as-is (mask or redact first).
  console.error(e.statusCode, e.message);
} else {
  throw e; // not from the SDK
}
}

Client-side validation

Two calls validate their input before hitting the network and raise a BadRequestError (or the language equivalent) immediately:

  • pix.getDetails requires exactly one of pixKey or qrCode. Passing both or neither fails locally.
  • consents.createJsr requires exactly one of payment (inline) or paymentId (reference).

Retries and timeouts

The client retries automatically, but only on idempotent calls (GET requests and token fetches) and only on NetworkError, RateLimitError (429, honoring Retry-After), or 5xx responses, using backoff. Non-idempotent calls — createJsr, processJsr, and other POST/PATCH methods — are never retried automatically, so a NetworkError there does not guarantee the request did not reach the backend.

OptionDefaultEffect
timeout30000 msPer-request deadline; a breach raises NetworkError.
maxRetries2Extra attempts on idempotent calls only.

Next steps