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:
parent
f9fd65a4bf
commit
05e69e6663
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user