From d1b8674575702cc772e34bf0199a21670c031b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Sat, 11 Apr 2026 01:25:59 +0200 Subject: [PATCH] Handle Overpass rate limit returned as 200 with error body Overpass API sometimes returns HTTP 200 with a plain-text error body containing "rate_limited" instead of a proper 429 status. Now checks response body for this pattern before attempting JSON parse. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/planner/app/lib/overpass.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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); }