Spaces:
Paused
Paused
Download src/lib/server/hooks/error.ts from Mike0021/chat-ui-agent-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/server/hooks/error.ts
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-demo/src/lib/server/hooks/error.ts
-
curl -L -o error.ts https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/server/hooks/error.ts
1.1 kB
| import type { HandleServerError } from "@sveltejs/kit"; | |
| import { logger } from "$lib/server/logger"; | |
| type HandleServerErrorInput = Parameters<HandleServerError>[0]; | |
| export async function handleServerError({ | |
| error, | |
| event, | |
| status, | |
| message, | |
| }: HandleServerErrorInput): Promise<App.Error> { | |
| // handle 404 | |
| if (event.route.id === null) { | |
| return { | |
| message: `Page ${event.url.pathname} not found`, | |
| }; | |
| } | |
| const errorId = crypto.randomUUID(); | |
| logger.error({ | |
| locals: event.locals, | |
| url: event.request.url, | |
| params: event.params, | |
| // Native Request/Headers instances contain private Undici accessors. Passing | |
| // them through Pino's path redactor can invoke those accessors with the wrong | |
| // receiver and crash the process while handling the original error. Keep the | |
| // diagnostic fields useful and deliberately omit request headers/body. | |
| request: { | |
| method: event.request.method, | |
| mode: event.request.mode, | |
| }, | |
| message, | |
| error, | |
| errorId, | |
| status, | |
| stack: error instanceof Error ? error.stack : undefined, | |
| }); | |
| return { | |
| message: "An error occurred", | |
| errorId, | |
| }; | |
| } | |