diff --git a/packages/shared/src/async/retryOnFailure.ts b/packages/shared/src/async/retryOnFailure.ts index d49154ac..84dd53e5 100644 --- a/packages/shared/src/async/retryOnFailure.ts +++ b/packages/shared/src/async/retryOnFailure.ts @@ -3,7 +3,7 @@ import { timeoutAfter } from "./timeoutAfter"; async function retry( asyncFunction: () => Promise, backOffStrategy: (iteration: number) => number, - onFail?: (error: unknown, attemptNumber: number) => void, + onFail?: (error: unknown, attemptNumber: number, maxAttempts: number) => void, maxAttempts: number = 5 ): Promise { let currentAttempt = 0; @@ -14,7 +14,7 @@ async function retry( return await asyncFunction(); } catch (error) { if (onFail) { - onFail(error, currentAttempt); + onFail(error, currentAttempt, maxAttempts); } if (currentAttempt == maxAttempts) { @@ -30,7 +30,7 @@ async function retry( export async function retryWithExponentialBackoff( asyncFunction: () => Promise, - onFail?: (error: unknown, attemptNumber: number) => void, + onFail?: (error: unknown, attemptNumber: number, maxAttempts: number) => void, maxTries?: number ): Promise { const backoff = (iteration: number) => 2 ** iteration * 100 + jitter(); @@ -40,7 +40,7 @@ export async function retryWithExponentialBackoff( export async function retryWithLinearBackoff( asyncFunction: () => Promise, - onFail?: (error: unknown, attemptNumber: number) => void, + onFail?: (error: unknown, attemptNumber: number, maxAttempts: number) => void, maxTries?: number ): Promise { const backoff = () => 100 + jitter(); diff --git a/packages/shared/src/recording/upload/uploadRecording.ts b/packages/shared/src/recording/upload/uploadRecording.ts index 88782a38..1a48d89a 100644 --- a/packages/shared/src/recording/upload/uploadRecording.ts +++ b/packages/shared/src/recording/upload/uploadRecording.ts @@ -233,8 +233,13 @@ async function uploadRecordingFileInParts({ abortController.signal ); }, - (error: any) => { - logger.debug(`Failed to upload part ${index + 1}; will be retried`, error); + (error: any, attemptNumber: number, maxAttempts: number) => { + let message = `Failed to upload part ${index + 1}`; + if (attemptNumber < maxAttempts && error.code !== "ENOENT") { + message += `; will be retried`; + } + logger.error(message, { error }); + if (error.code === "ENOENT") { throw error; }