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

Function extractApiErrorMessage

packages/oauth/src/api-error.ts:6–42  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

4const NESTED_ERROR_KEYS = ['message', 'error_description', 'detail', 'code', 'type'] as const;
5
6export function extractApiErrorMessage(value: unknown): string | undefined {
7 if (Array.isArray(value)) {
8 for (const item of value) {
9 const message = extractApiErrorMessage(item);
10 if (message !== undefined) return message;
11 }
12 return undefined;
13 }
14
15 if (!isRecord(value)) return undefined;
16
17 for (const key of DIRECT_ERROR_KEYS) {
18 const message = stringField(value, key);
19 if (message !== undefined) return message;
20 }
21
22 const error = value['error'];
23 const errorString = nonEmptyString(error);
24 if (errorString !== undefined) return errorString;
25
26 if (isRecord(error)) {
27 for (const key of NESTED_ERROR_KEYS) {
28 const message = stringField(error, key);
29 if (message !== undefined) return message;
30 }
31 }
32
33 const errors = value['errors'];
34 if (Array.isArray(errors)) {
35 for (const item of errors) {
36 const message = extractApiErrorMessage(item);
37 if (message !== undefined) return message;
38 }
39 }
40
41 return undefined;
42}
43
44export async function readApiErrorMessage(
45 response: Response,

Callers 4

pickErrorDetailFunction · 0.90
pollDeviceTokenFunction · 0.90
refreshAccessTokenFunction · 0.90
readApiErrorMessageFunction · 0.85

Calls 3

isRecordFunction · 0.90
stringFieldFunction · 0.70
nonEmptyStringFunction · 0.70

Tested by

no test coverage detected