Skip to content

Errors

A call can fail in two ways.

  • The bank declines. The request worked, but ResponseCode says no. The call resolves normally; check the code. initPayment succeeds with 1, every other call with "00". The response codes page lists what each code means, and RESPONSE_CODES gives you the same table in code.
  • The request fails. The SDK throws:
    • AmeriaHttpError when the bank answers with an HTTP error or a page that is not JSON (maintenance, a proxy error). It carries endpoint, status and the first 500 characters of body.
    • An error named TimeoutError when the bank does not answer within timeoutMs.
    • TypeError or RangeError for invalid input, before any request is sent.
errors.ts
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;
}
}