( fn: () => Promise<T>, retries: number = CONFIG.MAX_RETRIES )
| 60 | } |
| 61 | |
| 62 | async function withRetry<T>( |
| 63 | fn: () => Promise<T>, |
| 64 | retries: number = CONFIG.MAX_RETRIES |
| 65 | ): Promise<T> { |
| 66 | let lastError: unknown; |
| 67 | for (let attempt = 1; attempt <= retries; attempt++) { |
| 68 | try { |
| 69 | return await fn(); |
| 70 | } catch (error) { |
| 71 | lastError = error; |
| 72 | if (classifyError(error) === "permanent" || attempt === retries) { |
| 73 | throw error; |
| 74 | } |
| 75 | const delay = CONFIG.RETRY_BASE_DELAY * Math.pow(2, attempt - 1); |
| 76 | await new Promise((resolve) => setTimeout(resolve, delay)); |
| 77 | } |
| 78 | } |
| 79 | throw lastError; |
| 80 | } |
| 81 | |
| 82 | class CosplayScraper { |
| 83 | private readonly client: AxiosInstance; |
no test coverage detected