fix(recovery): restore source removed by production documentation merge
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* app/api/siax-error-mapping.ts — shared error mapper for the LEGACY routes
|
||||
* outside the /api/0pt matcher (`app/api/orders*`, `/subscriptions`,
|
||||
* `/payments/*`, `/webhooks/stripe`, `/admin/metrics`).
|
||||
*
|
||||
* 0pt#53: `getSqlForDurableStore` (lib/db.ts) throws
|
||||
* `SiaxError("DEPENDENCY_UNAVAILABLE")` (httpStatus 503, retryable) when a
|
||||
* money-bearing store would otherwise fall back to an in-memory Map in a
|
||||
* production runtime. The /api/0pt/* surface already maps that error via
|
||||
* src/http/siax-error-response.ts; these legacy routes did not, so the
|
||||
* documented 503 DEPENDENCY_UNAVAILABLE leaked as Next's opaque 500.
|
||||
*
|
||||
* The helpers preserve each route's OWN typed error contract
|
||||
* (IdempotencyKeyConflictError -> 409, etc.) and only ADD the SiaxError
|
||||
* branch — a plain rethrow is deliberately avoided because App Router turns
|
||||
* any uncaught thrown SiaxError into a generic 500 with no error body.
|
||||
*/
|
||||
import { NextResponse } from "next/server";
|
||||
import { SiaxError } from "@/src/platform/errors";
|
||||
|
||||
export function isSiaxError(error: unknown): error is SiaxError {
|
||||
return error instanceof SiaxError;
|
||||
}
|
||||
|
||||
/** Map a caught error to a NextResponse: SiaxError -> its pinned status/body. */
|
||||
export function siaxErrorResponseForLegacy(error: SiaxError): NextResponse {
|
||||
return NextResponse.json(error.toJSON(), { status: error.httpStatus });
|
||||
}
|
||||
Reference in New Issue
Block a user