| 20 | } |
| 21 | |
| 22 | async function fetchWithTimeout(url, options = {}) { |
| 23 | const timeoutMs = options.timeoutMs || config.requestTimeoutMs || 12000; |
| 24 | const controller = new AbortController(); |
| 25 | const timer = setTimeout(() => controller.abort(), timeoutMs); |
| 26 | const { timeoutMs: _timeoutMs, ...fetchOptions } = options; |
| 27 | |
| 28 | try { |
| 29 | return await fetch(url, { |
| 30 | ...fetchOptions, |
| 31 | signal: fetchOptions.signal || controller.signal |
| 32 | }); |
| 33 | } finally { |
| 34 | clearTimeout(timer); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | async function request(url, options = {}) { |
| 39 | const retries = Number.isInteger(options.retries) ? options.retries : (config.requestRetries || 0); |