fix: 统一错误出口并把 user 服务非 2xx 视为故障
- 新增最外层错误中间件:body-parser 的 400/413 等也转成约定 JSON, 客户端只收通用文案,5xx 详情仅进日志 - token 校验对 user 服务非 2xx 抛错而非按未登录处理, 避免服务抖动时在线用户被负缓存 60 秒踢回登录页
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user