1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-26 01:17:00 +02:00

fix: not crash if addon http post throws (#738)

added try/catch logic around fetchRetry function so that we do not
crash if addon fetch call throws
This commit is contained in:
Ivar Conradi Østhus 2021-02-26 13:46:56 +01:00 committed by GitHub
parent f9fd65a4bf
commit 05e69e6663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,16 +28,36 @@ class Addon {
async fetchRetry(url, options = {}, retries = 1, backoff = 300) {
const retryCodes = [408, 500, 502, 503, 504, 522, 524];
const res = await fetch(url, options);
if (res.ok) {
try {
const res = await fetch(url, options);
if (res.ok) {
return res;
}
if (retries > 0 && retryCodes.includes(res.status)) {
setTimeout(() => {
return this.fetchRetry(
url,
options,
retries - 1,
backoff * 2,
);
}, backoff);
}
return res;
} catch (error) {
this.logger.warn(error);
if (retries > 0) {
setTimeout(() => {
return this.fetchRetry(
url,
options,
retries - 1,
backoff * 2,
);
}, backoff);
}
return { status: 500 };
}
if (retries > 0 && retryCodes.includes(res.status)) {
setTimeout(() => {
return this.fetchRetry(url, options, retries - 1, backoff * 2);
}, backoff);
}
return res;
}
}