Make retries recurse backwards
This commit is contained in:
parent
760cc2d718
commit
eaabc3aae9
1 changed files with 3 additions and 3 deletions
|
@ -23,7 +23,7 @@ export async function downloadFile(url: string, file: string, options: RequestOp
|
||||||
export function simpleReq(
|
export function simpleReq(
|
||||||
url: string,
|
url: string,
|
||||||
options: RequestOptions = {},
|
options: RequestOptions = {},
|
||||||
retries = 0,
|
retries = 10,
|
||||||
backoffDelay = 1000
|
backoffDelay = 1000
|
||||||
): Promise<IncomingMessage> {
|
): Promise<IncomingMessage> {
|
||||||
return new Promise<IncomingMessage>((resolve, reject) => {
|
return new Promise<IncomingMessage>((resolve, reject) => {
|
||||||
|
@ -33,10 +33,10 @@ export function simpleReq(
|
||||||
if (statusCode! >= 300) return simpleReq(headers.location!, options).then(resolve).catch(reject);
|
if (statusCode! >= 300) return simpleReq(headers.location!, options).then(resolve).catch(reject);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}).on("error", err => {
|
}).on("error", err => {
|
||||||
if (retries > 10) {
|
if (retries < 0) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => resolve(simpleReq(url, options, retries + 1, backoffDelay * 2)), backoffDelay);
|
setTimeout(() => resolve(simpleReq(url, options, retries - 1, backoffDelay * 2)), backoffDelay);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue