Errors
A call can fail in two ways.
- The bank declines. The request worked, but
ResponseCodesays no. The call resolves normally; check the code.initPaymentsucceeds with1, every other call with"00". The response codes page lists what each code means, andRESPONSE_CODESgives you the same table in code. - The request fails. The SDK throws:
AmeriaHttpErrorwhen the bank answers with an HTTP error or a page that is not JSON (maintenance, a proxy error). It carriesendpoint,statusand the first 500 characters ofbody.- An error named
TimeoutErrorwhen the bank does not answer withintimeoutMs. TypeErrororRangeErrorfor invalid input, before any request is sent.
import { AmeriaHttpError, RESPONSE_CODES } from "@ameria/vpos-sdk";import { ameria } from "./client.js";
try { const details = await ameria.getPaymentDetails("PAYMENT-ID"); if (details.ResponseCode !== "00") { // A business decline: look up what the code means. const reason = RESPONSE_CODES[details.ResponseCode]; console.log(details.ResponseCode, reason?.description); }} catch (error) { if (error instanceof AmeriaHttpError) { // The bank answered with an HTTP error or a non-JSON page. console.error(error.endpoint, error.status, error.body); } else if (error instanceof Error && error.name === "TimeoutError") { // No answer within timeoutMs (30 s by default). The payment state is // unknown: check it again with getPaymentDetails before retrying. } else { throw error; }}