(config: Config, opts: RequestOpts)
| 79 | } |
| 80 | |
| 81 | export 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 | } |
no test coverage detected