Fix retries
This commit is contained in:
@@ -28,6 +28,7 @@ export default class PlaceRoute extends Route {
|
|||||||
try {
|
try {
|
||||||
const poi = await this.osm.getPoiById(id);
|
const poi = await this.osm.getPoiById(id);
|
||||||
if (poi) {
|
if (poi) {
|
||||||
|
console.debug('Found OSM POI:', poi);
|
||||||
// Map to our Place schema so the sidebar understands it
|
// Map to our Place schema so the sidebar understands it
|
||||||
return {
|
return {
|
||||||
title: poi.tags.name || poi.tags['name:en'] || 'Untitled Place',
|
title: poi.tags.name || poi.tags['name:en'] || 'Untitled Place',
|
||||||
|
|||||||
@@ -41,9 +41,19 @@ out center;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchWithRetry(url, options = {}, retries = 1) {
|
async fetchWithRetry(url, options = {}, retries = 3) {
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
if (retries > 0 && e.name !== 'AbortError') {
|
if (retries > 0 && e.name !== 'AbortError') {
|
||||||
console.log(`Retrying Overpass request... (${retries} left)`);
|
console.log(`Retrying Overpass request... (${retries} left)`);
|
||||||
|
|||||||
Reference in New Issue
Block a user