SDK ReferenceError Handling

Error Handling

SDK Error Handling

All SDKs throw an AparaError when an API call fails. Catch AparaError for structured API errors, and a generic exception for network/connection failures.

Error Properties

PropertyNode.jsPythonTypeDescription
Messageerror.messagestr(e)stringHuman-readable error message
Status codeerror.statusCodee.status_codenumberHTTP status code, e.g. 400, 401, 500
Response bodyerror.responseDatae.response_dataanyRaw JSON response from the API

Node.js

const { AparaPaymentAPI, AparaError } = require("apara-checkout");

try {
  const paymentUrl = await client.createPaymentInvoice({ /* ... */ });
} catch (error) {
  if (error instanceof AparaError) {
    console.error("Apara API Error:", error.message);
    console.error("HTTP Status:", error.statusCode);
    console.error("API Response:", error.responseData);
  } else {
    console.error("Unexpected error:", error.message);
  }
}

Python

from apara import AparaPaymentAPI, AparaError

try:
    payment_url = api.create_payment_invoice(request)
except AparaError as e:
    print("API Error:   ", e)
    print("Status Code: ", e.status_code)
    print("Response:    ", e.response_data)
except Exception as e:
    print("Unexpected error:", e)

Java

try {
    String paymentUrl = api.createPaymentInvoice(request);
    System.out.println("Payment URL: " + paymentUrl);
} catch (aparaError e) {
    System.err.println("Error: " + e.getMessage());
    System.err.println("Status Code: " + e.getStatusCode());
    System.err.println("Response: " + e.getResponseData());
}

PHP

try {
    $paymentUrl = $api->createPaymentInvoice($paymentData);
    echo 'Checkout URL: ' . $paymentUrl . PHP_EOL;
} catch (AparaError $e) {
    echo 'API Error   : ' . $e->getMessage() . PHP_EOL;
    echo 'Status Code : ' . $e->getStatusCode() . PHP_EOL;
    echo 'Response    : ' . json_encode($e->getResponseData(), JSON_PRETTY_PRINT) . PHP_EOL;
}

Common HTTP Status Codes

StatusMeaningCommon cause
400Bad RequestMissing required fields or invalid parameter values
401UnauthorizedInvalid or missing API keys
404Not FoundpaymentLinkId does not exist in your account
500Server ErrorTemporary Apara API issue — retry with backoff