diff --git a/utils/retry/src/__test__/decorator.test.ts b/utils/retry/src/__test__/decorator.test.ts index c684ab7635..07ed41f1cd 100644 --- a/utils/retry/src/__test__/decorator.test.ts +++ b/utils/retry/src/__test__/decorator.test.ts @@ -43,6 +43,7 @@ describe('Retryable decorator', () => { it('should retry failed operations', async () => { // Create a test class with decorated method that fails initially then succeeds + const error = new Error('First attempt failed') class TestService { callCount = 0 @@ -50,7 +51,7 @@ describe('Retryable decorator', () => { async testMethod (param1: string, param2: number): Promise { this.callCount++ if (this.callCount === 1) { - throw new Error('First attempt failed') + throw error } return `${param1}-${param2}` } @@ -68,7 +69,7 @@ describe('Retryable decorator', () => { expect(mockLogger.warn).toHaveBeenCalledWith( expect.stringContaining('testMethod failed'), expect.objectContaining({ - error: 'First attempt failed', + error, attempt: 1 }) ) diff --git a/utils/retry/src/retry.ts b/utils/retry/src/retry.ts index 2345ef338d..cb2950d533 100644 --- a/utils/retry/src/retry.ts +++ b/utils/retry/src/retry.ts @@ -71,25 +71,25 @@ export async function withRetry ( while (attempt <= config.maxRetries) { try { return await operation() - } catch (err: any) { - lastError = err + } catch (error: any) { + lastError = error const isLastAttempt = attempt >= config.maxRetries if (isLastAttempt) { logger.error(`${operationName} failed after ${attempt} attempts`, { - error: err.message, + error, attempt, maxRetries: config.maxRetries }) - throw err + throw error } - if (!config.isRetryable(err)) { + if (!config.isRetryable(error)) { logger.error(`${operationName} failed with non-retriable error`, { - error: err.message, + error, attempt, maxRetries: config.maxRetries }) - throw err + throw error } // Calculate next delay with jitter @@ -100,7 +100,7 @@ export async function withRetry ( const actualDelay = Math.min(delayMs + jitterAmount, config.maxDelayMs) logger.warn(`${operationName} failed, retrying in ${Math.round(actualDelay)}ms`, { - error: err.message, + error, attempt, nextAttempt: attempt + 1, delayMs: Math.round(actualDelay)