From 83009c2b9bf524d921124e91a4c5e8d52658d50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Wed, 25 Mar 2026 00:03:15 +0100 Subject: [PATCH] Fix withDb: re-throw React Router ErrorResponseImpl React Router's data() throws ErrorResponseImpl, not Response. Check for objects with status + data properties to catch both Response and ErrorResponseImpl, preventing withDb from swallowing 404s as 503s. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/db/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 46f0108..df18f2e 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -21,7 +21,13 @@ export type Database = ReturnType; export function withDb(handler: () => Promise): Promise { return handler().catch((error) => { // Re-throw React Router responses (redirects, data() throws) - if (error instanceof Response) throw error; + // Check for Response, ErrorResponseImpl, or anything with a status property + if ( + error instanceof Response || + (error && typeof error === "object" && "status" in error && "data" in error) + ) { + throw error; + } // Any other error from a DB-wrapped handler is treated as DB unavailable const message = error instanceof Error ? error.message : String(error);