Download packages/kap-server/src/error-handler.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/src/error-handler.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/kap-server/src/error-handler.ts
-
curl -L -o error-handler.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/src/error-handler.ts
1.15 kB
| import { ErrorCodes, isError2 } from '@moonshot-ai/agent-core-v2'; | |
| import { errEnvelope } from './envelope'; | |
| import { ErrorCode } from './protocol/error-codes'; | |
| import type { FastifyError } from 'fastify'; | |
| interface ErrorHandlerHost { | |
| setErrorHandler( | |
| handler: ( | |
| err: FastifyError, | |
| req: { id: string; log: { error: (obj: object | string, msg?: string) => void } }, | |
| reply: { status(code: number): { send(payload: unknown): void } }, | |
| ) => void, | |
| ): unknown; | |
| } | |
| export function installErrorHandler(app: ErrorHandlerHost): void { | |
| app.setErrorHandler((err, req, reply) => { | |
| const requestId = req.id; | |
| if (isError2(err) && err.code === ErrorCodes.CONFIG_INVALID) { | |
| reply | |
| .status(200) | |
| .send(errEnvelope(ErrorCode.VALIDATION_FAILED, err.message, requestId, err.stack)); | |
| return; | |
| } | |
| req.log.error({ err, request_id: requestId }, 'unhandled error'); | |
| reply.status(200).send( | |
| errEnvelope( | |
| ErrorCode.INTERNAL_ERROR, | |
| err.message !== undefined && err.message !== '' ? err.message : 'internal error', | |
| requestId, | |
| err.stack, | |
| ), | |
| ); | |
| }); | |
| } | |