From 89b0b81bdcc87e97a2f15ef1ad474b635a9ca7ab Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 5 Nov 2025 23:47:44 +0800 Subject: [PATCH] fix(web): add required headers for Nominatim reverse geocoding API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../MemoEditor/ActionButton/InsertMenu.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx b/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx index 39cee89fc..69975eccf 100644 --- a/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx +++ b/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx @@ -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);