| 703 | } |
| 704 | |
| 705 | async function requestJson( |
| 706 | fetchFn: typeof fetch, |
| 707 | url: string, |
| 708 | init: RequestInit, |
| 709 | ): Promise<Response> { |
| 710 | try { |
| 711 | return await fetchFn(url, init) |
| 712 | } catch (error) { |
| 713 | if (init.signal?.aborted) { |
| 714 | throw new APIUserAbortError() |
| 715 | } |
| 716 | if (error instanceof Error && error.name === 'TimeoutError') { |
| 717 | throw new APIConnectionTimeoutError({ message: error.message }) |
| 718 | } |
| 719 | throw new APIConnectionError({ |
| 720 | message: error instanceof Error ? error.message : 'Connection error.', |
| 721 | cause: error instanceof Error ? error : undefined, |
| 722 | }) |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | function buildHeaders( |
| 727 | providerType: OpenAICompatibleProviderType, |