Skip to content

🎥 Make videos programmatically with React

retry on connResetException: aborted (fix shaky lambda test)

Jonny Burger9c3942ea61ea
diff --git a/packages/renderer/src/assets/download-file.ts b/packages/renderer/src/assets/download-file.ts
index 0d0fe651a0..90145e808f 100644
--- a/packages/renderer/src/assets/download-file.ts
+++ b/packages/renderer/src/assets/download-file.ts
@@ -4,11 +4,7 @@ import {readFile} from './read-file';
type Response = {sizeInBytes: number; to: string};
-export const downloadFile = ({
- onProgress,
- url,
- to: toFn,
-}: {
+type Options = {
url: string;
to: (contentDisposition: string | null, contentType: string | null) => string;
onProgress:
@@ -18,7 +14,9 @@ export const downloadFile = ({
totalSize: number | null;
}) => void)
| undefined;
-}) => {
+};
+
+const downloadFileWithoutRetries = ({onProgress, url, to: toFn}: Options) => {
return new Promise<Response>((resolve, reject) => {
let rejected = false;
let resolved = false;
@@ -121,3 +119,23 @@ export const downloadFile = ({
});
});
};
+
+export const downloadFile = async (
+ options: Options,
+ retries = 2
+): Promise<Response> => {
+ try {
+ const res = await downloadFileWithoutRetries(options);
+ return res;
+ } catch (err) {
+ if ((err as Error).message === 'aborted') {
+ if (retries === 0) {
+ throw err;
+ }
+
+ return downloadFile(options, retries - 1);
+ }
+
+ throw err;
+ }
+};