fix: 外部 API 错误处理 + 导航 URL 校验 + reset/narrow 错误反馈
- #22: 高德 API fetch 加 try/catch,失败返回 503 而非泛化 500 - #23: buildNavUrl 校验 location.split(",") 结果长度和非空 - #24: handleReset/handleNarrow 检查 res.ok,失败时 toast 提示
This commit is contained in:
@@ -2,8 +2,10 @@ import type { Restaurant } from "@/types";
|
||||
|
||||
export function buildNavUrl(restaurant: Restaurant): string {
|
||||
if (restaurant.location) {
|
||||
const [lng, lat] = restaurant.location.split(",");
|
||||
return `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(restaurant.name)}&callnative=1`;
|
||||
const parts = restaurant.location.split(",");
|
||||
if (parts.length === 2 && parts[0] && parts[1]) {
|
||||
return `https://uri.amap.com/marker?position=${parts[0]},${parts[1]}&name=${encodeURIComponent(restaurant.name)}&callnative=1`;
|
||||
}
|
||||
}
|
||||
return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(restaurant.name)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user