Spaces:
Build error
Build error
Download src/lib/error-capture.ts from launch-calcium/Grabber-In-Tanstack-LlmDesk: direct link, hf CLI and curl.
- Browser
- Download file 906 Bytes
-
https://huggingface.co/spaces/launch-calcium/Grabber-In-Tanstack-LlmDesk/resolve/main/src/lib/error-capture.ts
- Command line
-
hf download hf://spaces/launch-calcium/Grabber-In-Tanstack-LlmDesk/src/lib/error-capture.ts
-
curl -L -o error-capture.ts https://huggingface.co/spaces/launch-calcium/Grabber-In-Tanstack-LlmDesk/resolve/main/src/lib/error-capture.ts
906 Bytes
| // 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; | |
| } | |