Core concepts
Error reference
Every error code checkoutOs returns, its HTTP status, and what to do about it.
All errors extend AppError, so the error middleware can format a response without any
switch statements or instanceof chains. Plain Error objects are never thrown from domain
code.
abstract class AppError extends Error {
abstract readonly httpStatus: number;
readonly code: ErrorCodeValue;
readonly details: Record<string, unknown>;
readonly isOperational: boolean;
}isOperational decides the log level, nothing else: true means the client sent something
bad and logs at warn; false means an unexpected system failure and logs at error.
Response shape
{
"success": false,
"error": {
"code": "REFUND_NOT_ALLOWED",
"message": "Refunds are only allowed on successful payments",
"details": { "chkId": "chk_a1b2c3d4e5f6a7b8" }
}
}400 — bad request
| Code | Error class | Cause |
|---|---|---|
INVALID_AMOUNT | InvalidAmountError | Amount is not a positive integer in paise |
INVALID_ORDER_ID | InvalidOrderIdError | Over 64 chars, or outside /^[A-Za-z0-9_.-]+$/ |
MISSING_IDEMPOTENCY_KEY | IdempotencyKeyMissingError | Idempotency-Key header absent |
INVALID_IDEMPOTENCY_KEY | IdempotencyKeyInvalidError | Header is not a UUID |
IDEMPOTENCY_KEY_REUSED | IdempotencyKeyReusedError | Same key, different payload |
PAYTM_PHONE_REQUIRED | PaytmPhoneRequiredError | Paytm requires customerPhone |
401 — unauthorized
| Code | Error class | Cause |
|---|---|---|
GATEWAY_INVALID_SIGNATURE | GatewayInvalidSignatureError | Webhook signature or checksum did not verify |
404 — not found
| Code | Error class | Cause |
|---|---|---|
PAYMENT_NOT_FOUND | PaymentNotFoundError | No record for that chk_ ID |
REFUND_NOT_FOUND | RefundNotFoundError | No record for that ref_ ID |
409 — conflict
| Code | Error class | Cause |
|---|---|---|
REQUEST_IN_PROGRESS | IdempotencyRequestInProgressError | The first request with this key is still running |
ORDER_CREATION_IN_PROGRESS | OrderCreationInProgressError | Another request holds the reservation for this orderId |
ORDER_ID_AMOUNT_MISMATCH | OrderIdAmountMismatchError | orderId exists with a different amount |
ORDER_ID_CURRENCY_MISMATCH | OrderIdCurrencyMismatchError | orderId exists with a different currency |
422 — unprocessable
The request is well-formed but cannot be acted on.
| Code | Error class | Cause |
|---|---|---|
REFUND_NOT_ALLOWED | RefundNotAllowedError | Payment is not SUCCESS / PARTIALLY_REFUNDED, or no webhook has set gatewayPaymentId yet |
REFUND_AMOUNT_EXCEEDS_PAYMENT | RefundAmountExceedsPaymentError | Refund would exceed the original amount |
500 — internal
| Code | Error class | Cause |
|---|---|---|
INTERNAL_ERROR | — | Unhandled failure; no internals are leaked |
502 — bad gateway
| Code | Error class | Cause |
|---|---|---|
PAYMENT_CREATION_FAILED | PaymentCreationFailedError | Gateway returned an unexpected response on create |
REFUND_FAILED | RefundFailedError | Gateway returned an unexpected response on refund |
GATEWAY_MAPPING_ERROR | GatewayMappingError | Gateway returned a status string checkoutOs does not recognize |
Never silently map an unknown status
GatewayMappingError exists so that a gateway shipping a new status string produces a loud
502 instead of being quietly coerced into FAILED. Guessing here means mis-reporting money
movement. Fail fast.
503 / 504 — gateway and store availability
| Code | Error class | Cause |
|---|---|---|
GATEWAY_UNAVAILABLE | GatewayUnavailableError | No plugin registered, the gateway is unreachable, or a gateway operation is unsupported |
STORE_ERROR | StoreError | Redis read or write failed |
GATEWAY_TIMEOUT | GatewayTimeoutError | Upstream call exceeded its timeout |