import type { SmsConfig } from '../types/smsTypes.ts' export async function fetchWithRetry( url: string, options: { method: string headers: Record body: string timeout: number maxRetries: number } ): Promise { let lastError: unknown = null for (let attempt = 0; attempt <= options.maxRetries; attempt++) { try { const controller = new AbortController() const timeoutId = setTimeout( () => controller.abort(), options.timeout ) const response = await fetch(url, { ...options, signal: controller.signal }) clearTimeout(timeoutId) return response } catch (error) { lastError = error instanceof Error ? error : new Error(String(error)) if (attempt < options.maxRetries) { await new Promise(resolve => setTimeout(resolve, 1000 * (attempt + 1))) } } } throw lastError instanceof Error ? lastError : new Error(String(lastError || '请求失败')) }