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:
2026-02-26 20:20:59 +08:00
parent dfb3cfa136
commit cf88d3a1d2
5 changed files with 58 additions and 23 deletions
+7 -2
View File
@@ -141,8 +141,13 @@ export const POST = apiHandler(async (req) => {
url.searchParams.set("keywords", cuisine);
}
const amapRes = await fetch(url.toString());
const amapData = await amapRes.json();
let amapData;
try {
const amapRes = await fetch(url.toString());
amapData = await amapRes.json();
} catch {
throw new ApiError("位置服务暂时不可用,请稍后重试", 503);
}
let restaurants: Restaurant[] = [];
if (amapData.status === "1" && amapData.pois?.length > 0) {