From 023432011bf6f2fe2504b0899a3306183b5ea78b Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 7 Aug 2026 04:12:38 +0000 Subject: [PATCH] Modified by www.SourceFiles.app --- src/lib/error-capture.ts | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/lib/error-capture.ts diff --git a/src/lib/error-capture.ts b/src/lib/error-capture.ts deleted file mode 100644 index 171c9b5..0000000 --- a/src/lib/error-capture.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Captures the original Error out-of-band so server.ts can recover the stack -// when h3 has already swallowed the throw into a generic 500 Response. - -let lastCapturedError: { error: unknown; at: number } | undefined; -const TTL_MS = 5_000; - -function record(error: unknown) { - lastCapturedError = { error, at: Date.now() }; -} - -if (typeof globalThis.addEventListener === "function") { - globalThis.addEventListener("error", (event) => record((event as ErrorEvent).error ?? event)); - globalThis.addEventListener("unhandledrejection", (event) => - record((event as PromiseRejectionEvent).reason), - ); -} - -export function consumeLastCapturedError(): unknown { - if (!lastCapturedError) return undefined; - if (Date.now() - lastCapturedError.at > TTL_MS) { - lastCapturedError = undefined; - return undefined; - } - const { error } = lastCapturedError; - lastCapturedError = undefined; - return error; -}