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

Function toKimiErrorPayload

packages/agent-core/src/errors/serialize.ts:67–142  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

65 * the wire.
66 */
67export function toKimiErrorPayload(error: unknown): KimiErrorPayload {
68 if (isKimiError(error)) {
69 return {
70 code: error.code,
71 message: error.message,
72 name: error.name,
73 details: error.details,
74 retryable: KIMI_ERROR_INFO[error.code].retryable,
75 };
76 }
77
78 if (error instanceof APIStatusError) {
79 const code: KimiErrorCode =
80 error.statusCode === 429
81 ? ErrorCodes.PROVIDER_RATE_LIMIT
82 : error.statusCode === 401
83 ? ErrorCodes.PROVIDER_AUTH_ERROR
84 : ErrorCodes.PROVIDER_API_ERROR;
85 return {
86 code,
87 message: sanitizeStatusErrorMessage(error.message),
88 name: error.name,
89 details: {
90 statusCode: error.statusCode,
91 requestId: error.requestId,
92 },
93 retryable: KIMI_ERROR_INFO[code].retryable,
94 };
95 }
96
97 if (error instanceof APIConnectionError || error instanceof APITimeoutError) {
98 return {
99 code: ErrorCodes.PROVIDER_CONNECTION_ERROR,
100 message: error.message,
101 name: error.name,
102 retryable: KIMI_ERROR_INFO[ErrorCodes.PROVIDER_CONNECTION_ERROR].retryable,
103 };
104 }
105
106 if (error instanceof APIEmptyResponseError) {
107 return {
108 code: ErrorCodes.PROVIDER_API_ERROR,
109 message: error.message,
110 name: error.name,
111 details: {
112 finishReason: error.finishReason,
113 rawFinishReason: error.rawFinishReason,
114 },
115 retryable: KIMI_ERROR_INFO[ErrorCodes.PROVIDER_API_ERROR].retryable,
116 };
117 }
118
119 if (error instanceof ChatProviderError) {
120 return {
121 code: ErrorCodes.PROVIDER_API_ERROR,
122 message: error.message,
123 name: error.name,
124 retryable: KIMI_ERROR_INFO[ErrorCodes.PROVIDER_API_ERROR].retryable,

Callers 5

serialize.test.tsFile · 0.90
mapRpcFunctionFunction · 0.90
runStepLoopMethod · 0.90
summarizeTurnErrorFunction · 0.90
compactionWorkerMethod · 0.90

Calls 2

isKimiErrorFunction · 0.85

Tested by

no test coverage detected