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) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-04-11 01:25:59 +02:00
parent c92d4cb4af
commit d1b8674575
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -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);
}