* 创建带超时的 fetch 包装器 * @param {string} url - 请求 URL * @param {Object} options - fetch 选项 * @param {number} timeout - 超时时间(毫秒) * @returns {Promise }
(url, options = {}, timeout = 30000)
| 362 | * @returns {Promise<Response>} |
| 363 | */ |
| 364 | async function fetchWithTimeout(url, options = {}, timeout = 30000) { |
| 365 | const controller = new AbortController(); |
| 366 | const timeoutId = setTimeout(() => controller.abort(), timeout); |
| 367 | |
| 368 | try { |
| 369 | const response = await fetch(url, { |
| 370 | ...options, |
| 371 | signal: controller.signal |
| 372 | }); |
| 373 | clearTimeout(timeoutId); |
| 374 | return response; |
| 375 | } catch (error) { |
| 376 | clearTimeout(timeoutId); |
| 377 | if (error.name === 'AbortError') { |
| 378 | throw new Error(`Request timeout after ${timeout}ms`); |
| 379 | } |
| 380 | throw error; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | module.exports = { |
| 385 | authenticate, |
nothing calls this directly
no outgoing calls
no test coverage detected