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) <noreply@anthropic.com>
This commit is contained in:
parent
b71117e4ca
commit
83009c2b9b
1 changed files with 7 additions and 1 deletions
|
|
@ -21,7 +21,13 @@ export type Database = ReturnType<typeof createDb>;
|
|||
export function withDb<T>(handler: () => Promise<T>): Promise<T> {
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue