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
| Property | Node.js | Python | Type | Description |
|---|---|---|---|---|
| Message | error.message | str(e) | string | Human-readable error message |
| Status code | error.statusCode | e.status_code | number | HTTP status code, e.g. 400, 401, 500 |
| Response body | error.responseData | e.response_data | any | Raw 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
| Status | Meaning | Common cause |
|---|---|---|
400 | Bad Request | Missing required fields or invalid parameter values |
401 | Unauthorized | Invalid or missing API keys |
404 | Not Found | paymentLinkId does not exist in your account |
500 | Server Error | Temporary Apara API issue — retry with backoff |
Was this page helpful?