diff --git a/apps/planner/app/lib/overpass.ts b/apps/planner/app/lib/overpass.ts index 48b1507..ed72409 100644 --- a/apps/planner/app/lib/overpass.ts +++ b/apps/planner/app/lib/overpass.ts @@ -118,7 +118,20 @@ export async function queryPois( throw new Error(`Overpass API error: ${response.status}`); } - const data = await response.json(); + const text = await response.text(); + + // Overpass sometimes returns 200 with rate limit error in the body + if (text.includes("rate_limited")) { + throw new OverpassRateLimitError(); + } + + let data; + try { + data = JSON.parse(text); + } catch { + throw new Error("Overpass API returned invalid JSON"); + } + return parseResponse(data, categories); }