fix(web): add required headers for Nominatim reverse geocoding API

Nominatim's usage policy requires a User-Agent header to identify the application. Added User-Agent and Accept headers to the reverse geocoding fetch request, and improved error handling to check HTTP response status.

Fixes #5222

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steven 2025-11-05 23:47:44 +08:00
parent 4c1d1c70d1
commit 89b0b81bdc
1 changed files with 12 additions and 2 deletions

View File

@ -78,8 +78,18 @@ const InsertMenu = observer((props: Props) => {
const handlePositionChange = (position: LatLng) => {
location.handlePositionChange(position);
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${position.lat}&lon=${position.lng}&format=json`)
.then((response) => response.json())
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${position.lat}&lon=${position.lng}&format=json`, {
headers: {
"User-Agent": "Memos/1.0 (https://github.com/usememos/memos)",
Accept: "application/json",
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
if (data?.display_name) {
location.setPlaceholder(data.display_name);