From e2be6e67dd113081c5d427261431d4623f82274e Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 26 Dec 2025 11:30:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AE=A4=E8=AF=81=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6):=20=E7=BB=9F=E4=B8=80=E8=AE=A4=E8=AF=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=B8=BA?= =?UTF-8?q?"=E8=AF=B7=E5=85=88=E7=99=BB=E5=BD=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化认证失败时的错误提示,不再使用原始业务错误信息,统一返回401状态码和"请先登录"提示,提升用户体验 --- server/internal/api/middleware.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/internal/api/middleware.go b/server/internal/api/middleware.go index 80dec46..50f4963 100644 --- a/server/internal/api/middleware.go +++ b/server/internal/api/middleware.go @@ -140,16 +140,10 @@ func withAuth(apiDomain string) func(http.Handler) http.Handler { // 检查认证是否成功(支持 HTTP 状态码和业务 code) if resp.StatusCode != http.StatusOK || authResp.Code != 200 { - // 优先使用业务返回的错误信息 - errorMsg := authResp.Message - if errorMsg == "" { - errorMsg = "认证失败" - } - // 返回原始的业务错误码和消息 - responseBody := fmt.Sprintf("{\"code\":%d,\"message\":\"%s\",\"data\":null}", authResp.Code, errorMsg) + // 所有认证错误都显示"请先登录" w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusUnauthorized) - w.Write([]byte(responseBody)) + w.Write([]byte("{\"code\":401,\"message\":\"请先登录\",\"data\":null}")) return }