From eaabc3aae9a8fc44f1887c5dc4c4a2537e190515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vani=C5=A1?= Date: Mon, 11 Mar 2024 13:47:31 +0100 Subject: [PATCH] Make retries recurse backwards --- src/main/utils/http.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/utils/http.ts b/src/main/utils/http.ts index f4dd9c5..3a336f8 100644 --- a/src/main/utils/http.ts +++ b/src/main/utils/http.ts @@ -23,7 +23,7 @@ export async function downloadFile(url: string, file: string, options: RequestOp export function simpleReq( url: string, options: RequestOptions = {}, - retries = 0, + retries = 10, backoffDelay = 1000 ): Promise { return new Promise((resolve, reject) => { @@ -33,10 +33,10 @@ export function simpleReq( if (statusCode! >= 300) return simpleReq(headers.location!, options).then(resolve).catch(reject); resolve(res); }).on("error", err => { - if (retries > 10) { + if (retries < 0) { reject(err); } else { - setTimeout(() => resolve(simpleReq(url, options, retries + 1, backoffDelay * 2)), backoffDelay); + setTimeout(() => resolve(simpleReq(url, options, retries - 1, backoffDelay * 2)), backoffDelay); } }); });