Fix retries

This commit is contained in:
2026-01-18 19:30:06 +07:00
parent 452ea8e674
commit 9de6cc0545
2 changed files with 13 additions and 2 deletions

View File

@@ -41,9 +41,19 @@ out center;
}
}
async fetchWithRetry(url, options = {}, retries = 1) {
async fetchWithRetry(url, options = {}, retries = 3) {
try {
return await fetch(url, options);
const res = await fetch(url, options);
if (!res.ok && retries > 0 && [502, 503, 504, 429].includes(res.status)) {
console.log(
`Overpass request failed with ${res.status}. Retrying... (${retries} left)`
);
await new Promise((r) => setTimeout(r, 1000));
return this.fetchWithRetry(url, options, retries - 1);
}
return res;
} catch (e) {
if (retries > 0 && e.name !== 'AbortError') {
console.log(`Retrying Overpass request... (${retries} left)`);