diff --git a/_shared.js b/_shared.js index 3c99a16..edc4101 100644 --- a/_shared.js +++ b/_shared.js @@ -6,12 +6,18 @@ const fetch_options_lookup = {}; const fetch_200 = async url => { const { hostname } = new URL(url); const fetch_options = await (fetch_options_lookup[hostname] ??= fs.promises.readFile(new URL(`./${hostname}.json`, import.meta.url), 'utf8').then(JSON.parse).catch(() => {})); - const resp = await fetch(url, fetch_options); - if (resp.status !== 200) { - console.log(url, fetch_options); - throw resp; + for (;;) { + const resp = await fetch(url, fetch_options); + if (resp.status === 200) { + return resp; + } else if (resp.status >= 500) { + console.log(`Got ${resp.status} - retrying: ${url}`); + await new Promise((res) => setTimeout(res, 5000)); + } else { + console.log(url, resp.status, JSON.stringify(await resp.text())); + throw resp; + } } - return resp; }; export const get = (url, params) => {