(
id: number,
params: { url: string; method: string; headers: Record<string, string>; body?: string },
)
| 556 | } |
| 557 | |
| 558 | async function handleAuthFetch( |
| 559 | id: number, |
| 560 | params: { url: string; method: string; headers: Record<string, string>; body?: string }, |
| 561 | ): Promise<void> { |
| 562 | if (!customFetch) { |
| 563 | sendError(id, -32601, "No custom fetch available"); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | try { |
| 568 | const resp = await customFetch(params.url, { |
| 569 | method: params.method, |
| 570 | headers: params.headers, |
| 571 | body: params.body, |
| 572 | }); |
| 573 | |
| 574 | const respHeaders: Record<string, string> = {}; |
| 575 | resp.headers.forEach((v: string, k: string) => { |
| 576 | respHeaders[k] = v; |
| 577 | }); |
| 578 | |
| 579 | const body = await resp.text(); |
| 580 | sendResult(id, { |
| 581 | status: resp.status, |
| 582 | headers: respHeaders, |
| 583 | body, |
| 584 | }); |
| 585 | } catch (err: unknown) { |
| 586 | const msg = err instanceof Error ? err.message : String(err); |
| 587 | sendError(id, -32603, `auth.fetch failed: ${msg}`); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | async function handleAuthFetchStream( |
| 592 | id: number, |
no test coverage detected