From b236eb60dad04170a0844f015445d5e3bc087508 Mon Sep 17 00:00:00 2001 From: Longyue Li Date: Fri, 5 Apr 2024 22:04:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=80=E6=94=BEErrUnauthorized?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BE=9B=E5=A4=96=E7=95=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: longyue0521 --- error.go | 1 + wrapper_func.go | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/error.go b/error.go index 3f0a0a8..9802ccd 100644 --- a/error.go +++ b/error.go @@ -17,3 +17,4 @@ package ginx import "github.com/ecodeclub/ginx/internal/errs" var ErrNoResponse = errs.ErrNoResponse +var ErrUnauthorized = errs.ErrUnauthorized diff --git a/wrapper_func.go b/wrapper_func.go index 89baf47..2a48f67 100644 --- a/wrapper_func.go +++ b/wrapper_func.go @@ -19,7 +19,6 @@ import ( "log/slog" "net/http" - "github.com/ecodeclub/ginx/internal/errs" "github.com/ecodeclub/ginx/session" "github.com/gin-gonic/gin" ) @@ -31,7 +30,7 @@ func W(fn func(ctx *Context) (Result, error)) gin.HandlerFunc { slog.Debug("不需要响应", slog.Any("err", err)) return } - if errors.Is(err, errs.ErrUnauthorized) { + if errors.Is(err, ErrUnauthorized) { slog.Debug("未授权", slog.Any("err", err)) ctx.AbortWithStatus(http.StatusUnauthorized) return @@ -57,7 +56,7 @@ func B[Req any](fn func(ctx *Context, req Req) (Result, error)) gin.HandlerFunc slog.Debug("不需要响应", slog.Any("err", err)) return } - if errors.Is(err, errs.ErrUnauthorized) { + if errors.Is(err, ErrUnauthorized) { slog.Debug("未授权", slog.Any("err", err)) ctx.AbortWithStatus(http.StatusUnauthorized) return @@ -93,7 +92,7 @@ func BS[Req any](fn func(ctx *Context, req Req, sess session.Session) (Result, e return } // 如果里面有权限校验,那么会返回 401 错误(目前来看,主要是登录态校验) - if errors.Is(err, errs.ErrUnauthorized) { + if errors.Is(err, ErrUnauthorized) { slog.Debug("未授权", slog.Any("err", err)) ctx.AbortWithStatus(http.StatusUnauthorized) return @@ -123,7 +122,7 @@ func S(fn func(ctx *Context, sess session.Session) (Result, error)) gin.HandlerF return } // 如果里面有权限校验,那么会返回 401 错误(目前来看,主要是登录态校验) - if errors.Is(err, errs.ErrUnauthorized) { + if errors.Is(err, ErrUnauthorized) { slog.Debug("未授权", slog.Any("err", err)) ctx.AbortWithStatus(http.StatusUnauthorized) return