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:
parent
c92d4cb4af
commit
d1b8674575
1 changed files with 14 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue