fix: handle HTML response from Nominatim geocoding (rate limit)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5133674eb3
commit
36cb2bd3e5
|
|
@ -61,6 +61,11 @@ func (g *nominatimGeocoder) GetAddressFromCoordinates(latitude, longitude float6
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
log.Printf("Nominatim returned HTTP %d for lat=%f lon=%f", resp.StatusCode, latitude, longitude)
|
||||||
|
return "", fmt.Errorf("geocoding service returned status %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
// Read full response body
|
// Read full response body
|
||||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -68,6 +73,10 @@ func (g *nominatimGeocoder) GetAddressFromCoordinates(latitude, longitude float6
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(bodyBytes) > 0 && bodyBytes[0] == '<' {
|
||||||
|
log.Printf("Nominatim returned HTML instead of JSON (possible rate limit) for lat=%f lon=%f", latitude, longitude)
|
||||||
|
return "", fmt.Errorf("geocoding service unavailable (rate limited or network error)")
|
||||||
|
}
|
||||||
|
|
||||||
var result NominatimResponse
|
var result NominatimResponse
|
||||||
if err := json.Unmarshal(bodyBytes, &result); err != nil {
|
if err := json.Unmarshal(bodyBytes, &result); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue