Error Handling
Failed API responses throw RequiplyError:
import { RequiplyError } from '@requiply/api-sdk';
try {
await requiply.sales.create({ lines: [{ saleItemId, quantity: 1 }], paymentMethod: 'liqpay' });
} catch (error) {
if (error instanceof RequiplyError && error.reason === 'client_email_required') {
console.error('LiqPay needs a client with an email');
} else {
throw error;
}
}
Error properties
| Property | What it holds |
|---|---|
status | HTTP response status, for example 400, 403, 404, 409, or 429. |
message | The API's human-readable message, with an HTTP-status fallback. Show it to people, but do not branch on its text. |
reason | Machine-readable reason, when the API gives one, for example feature_disabled. Branch on this. |
data | Extra fields the API sent with the error, including reason. |
details | The parsed response body, or the raw response text when it is not JSON. |
retryAfter | Seconds to wait, from the Retry-After header of a 429. |
Error reasons
reason is set by booking requests from publishable keys, by the Sales endpoints, and by sale lines on quotes and bookings:
reason | Status | Meaning |
|---|---|---|
request_only | 403 | A publishable key called bookings.create() without asRequest: true. |
feature_disabled | 403 | Enable sales is off, or the organization is not on the Advanced plan. |
selling_disabled | 403 | A publishable key asked for goods for sale while the organization does not sell to customers. |
out_of_stock | 409 | A publishable key asked for more units than are on the shelf. data.saleItemId names the product, data.availableQuantity says how many are left. |
invalid_lines | 400 | A line has no product or a quantity that is not a whole number above zero. |
duplicate_line | 400 | The same product appears in two lines. |
sale_item_not_found | 404 | A product does not exist in this organization. |
sale_item_archived | 409 | A product is archived and cannot be sold. |
invalid_payment | 400 | paymentMethod is not a known method. |
payment_method_unavailable | 400 | The organization has no active integration for that payment method. |
client_email_required | 400 | LiqPay sends the invoice by email, so the sale needs a client with an email. |
sale_not_found | 404 | The sale does not exist. |
New reasons can appear, so always keep a fallback branch. Most other errors, such as a missing field or an unknown booking, carry only status and message.
Rate limits
Each key can make 100 requests per minute. Further requests throw a RequiplyError with status 429 and retryAfter in seconds. In browsers retryAfter is missing, because the API does not expose the header across origins; wait a few seconds before retrying.
Refused bookings are not errors
bookings.create() does not throw when the organization cannot accept a booking, for example because the items are taken for those dates or the pickup is outside working hours. It resolves with success: false, a message, and sometimes a reason. See Bookings.
Errors that are not RequiplyError
Constructor validation and missing runtime APIs throw TypeError: a missing or empty apiKey, no available fetch, or a secret key used in the browser. Network failures and aborted requests reject with the error your fetch implementation throws.