(
baseUrl: string,
path: string,
apiKey: string | null | undefined,
signal?: AbortSignal,
)
| 105 | } |
| 106 | |
| 107 | async function fetchJson( |
| 108 | baseUrl: string, |
| 109 | path: string, |
| 110 | apiKey: string | null | undefined, |
| 111 | signal?: AbortSignal, |
| 112 | ): Promise<unknown> { |
| 113 | const headers: Record<string, string> = {}; |
| 114 | if (apiKey) headers.Authorization = `Bearer ${apiKey}`; |
| 115 | |
| 116 | const response = await fetch(`${baseUrl}${path}`, { headers, signal }); |
| 117 | |
| 118 | if (!response.ok) { |
| 119 | throw new PollinationsError( |
| 120 | `Failed to fetch model catalog from ${path}`, |
| 121 | "MODEL_CATALOG", |
| 122 | response.status, |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | return response.json(); |
| 127 | } |
| 128 | |
| 129 | async function fetchCatalogModels( |
| 130 | baseUrl: string, |
no test coverage detected