mirror of https://github.com/usememos/memos.git
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:
parent
4c1d1c70d1
commit
89b0b81bdc
|
|
@ -78,8 +78,18 @@ const InsertMenu = observer((props: Props) => {
|
||||||
const handlePositionChange = (position: LatLng) => {
|
const handlePositionChange = (position: LatLng) => {
|
||||||
location.handlePositionChange(position);
|
location.handlePositionChange(position);
|
||||||
|
|
||||||
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${position.lat}&lon=${position.lng}&format=json`)
|
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${position.lat}&lon=${position.lng}&format=json`, {
|
||||||
.then((response) => response.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) => {
|
.then((data) => {
|
||||||
if (data?.display_name) {
|
if (data?.display_name) {
|
||||||
location.setPlaceholder(data.display_name);
|
location.setPlaceholder(data.display_name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue