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
@@ -15,8 +15,13 @@ export const GET = apiHandler(async (req) => {
url.searchParams.set("location", `${lng},${lat}`);
url.searchParams.set("extensions", "base");
const res = await fetch(url.toString());
const data = await res.json();
let data;
try {
const res = await fetch(url.toString());
data = await res.json();
} catch {
throw new ApiError("位置服务暂时不可用,请稍后重试", 503);
}
if (data.status !== "1" || !data.regeocode) {
return NextResponse.json({ name: null });