Errors
The error response of the Altruon API, every documented error code and HTTP status, and what to do about each one.
When a request fails, the API responds with a 4xx or 5xx HTTP status and a JSON body with one error object. Branch on error.code. Show or log error.message.
Error response
{
"error": {
"code": "invalid_request",
"message": "Missing required field: paymentData.currency",
"details": {}
}
}errorobjectPresent on every failed request.
codestringMachine-readable error code. One of the codes below.
messagestringWhat went wrong, in plain English, for example Missing required field: paymentData.currency.
detailsobjectAdditional detail about the error. An empty object in the example above.
Error codes
| Code | Meaning | What to do |
|---|---|---|
invalid_request | A request parameter is missing or invalid. | Read error.message, then compare your body with the request fields. |
unauthorized | The secret key is missing or invalid. | Send your secret key in the x-secret-key header. See Authentication. |
invalid_line_item | A line item ID was not found or is not valid. | Check that every billingData.lineItems[].id exists on the billing platform behind billingPlatformId. |
invalid_billing_platform | The billing platform is not configured. | Connect the billing platform in the backoffice under Settings > Billing Platforms and send its ID in billingData.billingPlatformId. See Billing platforms. |
rate_limit_exceeded | Too many requests. | Retry with a backoff: wait before each retry, and wait longer each time. |
HTTP statuses
| Status | When | Returned by |
|---|---|---|
200 | The request succeeded. | Create a session |
400 | billingData.forceTrialPeriodDays is outside 1 to 730, or is combined with hostedPageConfigId. | Create a session |
401 | The secret key is missing or invalid. | Get transaction details |
404 | No transaction has the ID in the path. | Get transaction details |
Other 4xx, 5xx | The request failed. Read the error object. | Both endpoints |
Tell errors apart by error.code, not by the status alone.
Rejections at session creation
These requests are also rejected when you create a session:
| Request | Result | What to do |
|---|---|---|
| A trial with nothing due today, on an acquirer and payment method that does not support trials | An unsupported error | Use a combination from the trial matrix in Trials, or leave paymentMethod out so hosted checkout shows only the methods that support trials. |
A key in billingData.customerCustomFields that does not start with cf_ | The key is rejected | Prefix every key with cf_. |
A coupon in billingData.couponCodes that the billing platform does not know | The billing platform rejects it | Send coupon IDs or codes that exist on the billing platform. See Coupons. |
A forceTrialPeriodDays at the top level of the body is not an error. It is ignored, and no trial is forced. Nest it inside billingData.
Payment failures are not API errors
A declined or failed payment does not produce an error object. You learn about it in other places:
- In Altruon.js, the
onFailurecallback fires. See Callbacks. - Get transaction details returns the transaction with
statusset tofailedand the reason inerrorMessage. - Webhooks send
payment.failed. See Event types.
Handle errors in code
const response = await fetch(url, options);
const data = await response.json();
if (!response.ok) {
switch (data.error.code) {
case 'rate_limit_exceeded':
// Wait, then retry.
break;
case 'unauthorized':
// Wrong or missing secret key. Fix the configuration.
break;
case 'invalid_request':
case 'invalid_line_item':
case 'invalid_billing_platform':
default:
// The request cannot succeed as sent.
throw new Error(`${data.error.code}: ${data.error.message}`);
}
}