| 12 | |
| 13 | // Helper to create a mock function that fails a certain number of times |
| 14 | const createFailingFunction = ( |
| 15 | failures: number, |
| 16 | successValue: string = 'success', |
| 17 | ) => { |
| 18 | let attempts = 0; |
| 19 | return vi.fn(async () => { |
| 20 | attempts++; |
| 21 | if (attempts <= failures) { |
| 22 | // Simulate a retryable error |
| 23 | const error: HttpError = new Error(`Simulated error attempt ${attempts}`); |
| 24 | error.status = 500; // Simulate a server error |
| 25 | throw error; |
| 26 | } |
| 27 | return successValue; |
| 28 | }); |
| 29 | }; |
| 30 | |
| 31 | // Custom error for testing non-retryable conditions |
| 32 | class NonRetryableError extends Error { |