fix: 统一错误出口并把 user 服务非 2xx 视为故障

- 新增最外层错误中间件:body-parser 的 400/413 等也转成约定 JSON,
  客户端只收通用文案,5xx 详情仅进日志
- token 校验对 user 服务非 2xx 抛错而非按未登录处理,
  避免服务抖动时在线用户被负缓存 60 秒踢回登录页
This commit is contained in:
lik
2026-11-08 11:59:31 +08:00
parent d21f5da682
commit ffa6d8c1e3
3 changed files with 127 additions and 0 deletions
+5
View File
@@ -36,6 +36,11 @@ async function lookup(body) {
body: JSON.stringify(body),
signal: AbortSignal.timeout(LOOKUP_TIMEOUT),
});
// 非 2xx 视为服务故障而不是「token 无效」:曾把 5xx 当作未登录,
// 在线用户会被负缓存 60 秒,表现为莫名被踢回登录页
if (!res.ok) {
throw new Error(`user service responded ${res.status}`);
}
const data = await res.json();
return data?.data?.user || null;
}