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

Function postJson

packages/oauth/src/managed-feedback-upload.ts:83–122  ·  view source on GitHub ↗
(
  url: string,
  accessToken: string,
  body: unknown,
  opts: { timeoutMs?: number },
)

Source from the content-addressed store, hash-verified

81}
82
83async function postJson(
84 url: string,
85 accessToken: string,
86 body: unknown,
87 opts: { timeoutMs?: number },
88): Promise<{ readonly kind: 'ok'; readonly payload: unknown } | FetchFeedbackUploadError> {
89 const controller = new AbortController();
90 const timer = setTimeout(() => {
91 controller.abort();
92 }, opts.timeoutMs ?? 8000);
93 try {
94 const res = await fetch(url, {
95 method: 'POST',
96 headers: {
97 Authorization: `Bearer ${accessToken}`,
98 Accept: 'application/json',
99 'Content-Type': 'application/json',
100 },
101 body: JSON.stringify(body),
102 signal: controller.signal,
103 });
104 if (!res.ok) {
105 return {
106 kind: 'error',
107 status: res.status,
108 message: await readApiErrorMessage(res, `Feedback upload request failed: HTTP ${res.status}`),
109 };
110 }
111 const text = await res.text();
112 return { kind: 'ok', payload: text.length > 0 ? JSON.parse(text) : {} };
113 } catch (error) {
114 if (error instanceof Error && error.name === 'AbortError') {
115 return { kind: 'error', message: 'Feedback upload request timed out.' };
116 }
117 const msg = error instanceof Error ? error.message : String(error);
118 return { kind: 'error', message: `Feedback upload request failed: ${msg}` };
119 } finally {
120 clearTimeout(timer);
121 }
122}
123
124function feedbackBaseUrl(baseUrl?: string): string {
125 return (baseUrl ?? kimiCodeBaseUrl()).replace(/\/+$/, '');

Callers 2

Calls 3

readApiErrorMessageFunction · 0.90
abortMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected