From 9de6cc054562076144a3d4647fa82878dd9ac7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 18 Jan 2026 19:30:06 +0700 Subject: [PATCH] Fix retries --- app/routes/place.js | 1 + app/services/osm.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/routes/place.js b/app/routes/place.js index 9f9db6a..5da2bb0 100644 --- a/app/routes/place.js +++ b/app/routes/place.js @@ -28,6 +28,7 @@ export default class PlaceRoute extends Route { try { const poi = await this.osm.getPoiById(id); if (poi) { + console.debug('Found OSM POI:', poi); // Map to our Place schema so the sidebar understands it return { title: poi.tags.name || poi.tags['name:en'] || 'Untitled Place', diff --git a/app/services/osm.js b/app/services/osm.js index 1744bca..bade33a 100644 --- a/app/services/osm.js +++ b/app/services/osm.js @@ -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)`);