MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / sendMappedError

Function sendMappedError

packages/server/src/routes/tasks.ts:217–241  ·  view source on GitHub ↗

* Map a thrown error to the right envelope. See module header for the table. * * `TaskAlreadyFinishedError` is a SPECIAL case — REST.md §3.7 mandates * envelope `code: 40904` + `data: {cancelled: false}` for the idempotent * cancellation shape.

(
  reply: { send(payload: unknown): unknown },
  requestId: string,
  err: unknown,
)

Source from the content-addressed store, hash-verified

215 * cancellation shape.
216 */
217function sendMappedError(
218 reply: { send(payload: unknown): unknown },
219 requestId: string,
220 err: unknown,
221): void {
222 if (err instanceof TaskAlreadyFinishedError) {
223 reply.send({
224 code: ErrorCode.TASK_ALREADY_FINISHED,
225 msg: err.message,
226 data: { cancelled: false },
227 request_id: requestId,
228 details: { current_status: err.currentStatus },
229 });
230 return;
231 }
232 if (err instanceof TaskNotFoundError) {
233 reply.send(errEnvelope(ErrorCode.TASK_NOT_FOUND, err.message, requestId));
234 return;
235 }
236 if (err instanceof SessionNotFoundError) {
237 reply.send(errEnvelope(ErrorCode.SESSION_NOT_FOUND, err.message, requestId));
238 return;
239 }
240 throw err;
241}

Callers 1

registerTasksRoutesFunction · 0.70

Calls 2

errEnvelopeFunction · 0.90
sendMethod · 0.65

Tested by

no test coverage detected