check_login 无Token 返回401

This commit is contained in:
蒋海成 2025-02-22 17:32:25 +08:00
parent d9f1787d62
commit bbc0359100
2 changed files with 18 additions and 2 deletions

View File

@ -20,7 +20,7 @@ func CheckLogin(provider *api.AccountClientImpl) gin.HandlerFunc {
//如果没有登录
authorization := ctx.GetHeader(e.BoxAuthorization)
if authorization == "" {
service.Error(ctx, errors.New(e.ErrNotLogin))
service.NotLoginError(ctx, errors.New(e.ErrNotLogin))
return
}
@ -28,7 +28,7 @@ func CheckLogin(provider *api.AccountClientImpl) gin.HandlerFunc {
fmt.Println(jwt)
if err != nil {
service.Error(ctx, errors.New(e.ErrNotLogin))
service.NotLoginError(ctx, errors.New(e.ErrNotLogin))
return
}

View File

@ -70,3 +70,19 @@ func Retry(c *gin.Context, err error) {
c.Abort()
}
func NotLoginError(c *gin.Context, err error) {
errMsg := ""
if err != nil {
errMsg = err.Error()
}
c.JSON(http.StatusUnauthorized, Response{
Code: Failed,
Msg: errMsg,
Data: struct{}{},
})
c.Abort()
}