Last updated
Errors#
Interpret transport and application failures, preserve backend explanations, and recover without repeating financial effects.
Two layers of outcome#
An HTTP status describes the response at the transport level. The JSON envelope describes the application outcome. Inspect both. The existing KlemPay transport recognises responseCode values 00 and 000 as successful; an HTTP 200 with another code is handled as an unsuccessful operation.
{
"responseCode": "PAYUSR-006",
"responseMessage": "This invitation link is no longer valid. Ask for a new invitation",
"errors": ["This invitation link is no longer valid. Ask for a new invitation"]
}Display the backend's useful explanation in the affected form or page. Do not keep a loading indicator active after a rejected response, and do not replace a specific validation message with a generic success or unavailable state.
HTTP status categories#
| Status | Meaning to investigate | Recovery |
|---|---|---|
400 | Invalid or missing request data. | Correct the named fields against the endpoint schema before retrying. |
401 | Authentication was not accepted. | Check credentials, signature, timestamp, or session according to the controller. |
403 | Access is denied despite a received request. | Check scope, tenant, account permission, and backend explanation. |
404 | The endpoint or referenced resource was not found. | Check route, environment, and resource reference. |
409 | A duplicate or conflicting state may exist. | Retrieve the current operation; do not blindly create a new reference. |
422 | The request cannot satisfy validation or workflow rules. | Follow the returned field or business validation errors. |
429 | The service is limiting requests. | Honour Retry-After if supplied; otherwise use bounded backoff and jitter. |
500 | The service encountered an internal failure. | Preserve the reference and trace ID; reconcile writes before retrying. |
502 or 503 | An upstream service is unavailable or returned an invalid response. | Retry safe reads with limits; reconcile uncertain writes first. |
504 | A gateway stopped waiting for an upstream response. | Treat a submitted write as uncertain until its state is checked. |
These are standard HTTP interpretations, not an endpoint-specific guarantee. Always read the application message and confirmed controller contract alongside the status.
KlemPay codes encountered in the web application#
The table distinguishes behaviour implemented in the existing KlemPay web project from codes whose backend definitions were not supplied. The backend responseMessage and endpoint schema remain authoritative.
| Code | Verified context | Recommended response |
|---|---|---|
PAY-AUTH-001 | Authentication family; exact mapping is not established by the inspected frontend. | Show the backend explanation and inspect the controller's credentials or signing requirements. |
PAY-AUTH-002 | Authentication family; exact mapping is not established by the inspected frontend. | Preserve the backend message; do not assume password, OTP, or expiry semantics. |
PAY-AUTH-003 | Authentication family; exact mapping is not established by the inspected frontend. | Correct the issue named by the backend or ask support with a trace identifier. |
KLMS-502 | The authenticated transport treats this as a rejected session only when the message identifies an identity-verification failure. | Re-authenticate for that verified context; do not log out users for every occurrence of this code. |
PAY-BIL-006 | The bill-payment flow refreshes customer validation before retrying with the same external reference. | Revalidate, use the backend's product-controlled amount, and preserve the reference. |
PAY-BIL-007 | The bill-payment interface asks the user to check an unrecognised number. | Correct the customer number and validate it again. |
PAY-BIL-009 | The interface preserves the backend's allowed-amount explanation. | Enter an amount within the returned constraints. |
PAY-BIL-012 | A used payment reference is handled as a duplicate; an existing receipt is retrieved when its reference is available. | Check the original transaction before trying a new payment. |
PAY-BIL-014 | The interface reports insufficient balance. | Confirm available balance and funding; do not automatically increase or change the amount. |
PAYUSR-006 | The supplied invitation response reports an invalid or expired invitation. | Ask an administrator to send a new invitation. |
Parse errors without losing context#
Keep response codes as strings; converting 00 to a number destroys its exact representation. Validate that errors contains strings, preserve responseMessage, and validate successful responseData against the expected shape.
const successfulCodes = new Set(["00", "000"]);
const envelope = await response.json();
const messages = Array.isArray(envelope.errors)
? envelope.errors.filter((value) => typeof value === "string")
: [];
if (!response.ok || !successfulCodes.has(envelope.responseCode)) {
return {
ok: false,
message:
typeof envelope.responseMessage === "string"
? envelope.responseMessage
: "The request could not be completed.",
errors: messages,
responseCode: envelope.responseCode,
httpStatus: response.status,
};
}
return { ok: true, data: validateExpectedResponse(envelope.responseData) };A non-JSON response, malformed envelope, or wrong successful data shape is a protocol failure. Show a recoverable service message, record redacted diagnostics, and do not treat it as a successful transaction.
Decide whether a retry is safe#
Retry safe reads with a maximum attempt count and a short backoff. For writes, use the endpoint's documented idempotency mechanism and retrieve the original state when the outcome is uncertain.
Do not automatically retry validation, authentication, or permission errors without changing the cause. A duplicate-reference response requires reconciliation. A timeout requires an outcome check, not a new business intent.
Useful diagnostics#
When reporting an issue, include the environment, time, method, path, HTTP status, response code, sanitised response message, and returned trace identifier. Include the existing resource or operation reference only through an approved support channel.
Exclude API secrets, authorization headers, OTPs, full account numbers, personal identity data, and secret-bearing URLs. Support should be able to trace the request without receiving credentials.
Design a recoverable interface#
- Field validation stays beside the related field or form.
- Access failures explain the next action without exposing internal permission rules.
- Pending writes show the original reference and a status-check action.
- Page-loading failures show the actual backend explanation and a retry action.
- Background refresh failures preserve already readable content and disclose that the refresh failed.
- Every loading state ends on success, empty data, rejection, timeout, or an unexpected transport failure.