function fetchWithRetry()

in all_missing_uplifts.js [65:91]


function fetchWithRetry(url, trials = 0) {
  return fetch(url)
    .then((response) => {
      if (!response.ok) {
        throw new Error("Error while getting " + url);
      } else {
        return response;
      }
    })
    .catch((error) => {
      let timeout = Math.pow(2, trials) * 1000;

      if (timeout > 32000) {
        timeout = 32000;
      }

      if (trials > 64) {
        throw error;
      }

      return new Promise(function (resolve, reject) {
        setTimeout(() => {
          fetchWithRetry(url, trials + 1).then(resolve, reject);
        }, timeout);
      });
    });
}