(url, { headers = {}, timeoutMs = 15000 } = {})
| 187 | } |
| 188 | |
| 189 | async function fetchJsonWithTimeout(url, { headers = {}, timeoutMs = 15000 } = {}) { |
| 190 | const controller = new AbortController(); |
| 191 | const timer = setTimeout(() => controller.abort(), timeoutMs); |
| 192 | try { |
| 193 | const response = await fetch(url, { |
| 194 | method: "GET", |
| 195 | headers, |
| 196 | signal: controller.signal, |
| 197 | }); |
| 198 | const text = await response.text(); |
| 199 | let data = null; |
| 200 | try { |
| 201 | data = JSON.parse(text); |
| 202 | } catch {} |
| 203 | return { |
| 204 | ok: response.ok, |
| 205 | status: response.status, |
| 206 | data, |
| 207 | text, |
| 208 | }; |
| 209 | } finally { |
| 210 | clearTimeout(timer); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | function normalizeModelEntries(list, provider) { |
| 215 | if (!Array.isArray(list)) return []; |
no test coverage detected