MCPcopy
hub / github.com/MiniMax-AI/cli / requestJson

Function requestJson

src/client/http.ts:81–99  ·  view source on GitHub ↗
(config: Config, opts: RequestOpts)

Source from the content-addressed store, hash-verified

79}
80
81export async function requestJson<T>(config: Config, opts: RequestOpts): Promise<T> {
82 const res = await request(config, opts);
83 let data: T & { base_resp?: { status_code?: number; status_msg?: string } };
84 try {
85 data = (await res.json()) as T & { base_resp?: { status_code?: number; status_msg?: string } };
86 } catch {
87 const contentType = res.headers.get('content-type') || '';
88 throw new CLIError(
89 `API returned non-JSON response (${contentType || 'unknown type'}). Server may be experiencing issues.`,
90 ExitCode.GENERAL,
91 );
92 }
93
94 if (data.base_resp?.status_code && data.base_resp.status_code !== 0) {
95 throw mapApiError(200, { base_resp: data.base_resp }, opts.url);
96 }
97
98 return data;
99}

Callers 1

http.test.tsFile · 0.90

Calls 2

mapApiErrorFunction · 0.90
requestFunction · 0.85

Tested by

no test coverage detected