Add exception error manager

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-21 12:04:17 +08:00
parent 200614a5c9
commit 5dbbdc62e6
11 changed files with 157 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
package middleware
import (
"fmt"
"nixcn-cms/exception"
"nixcn-cms/pkgs/authtoken"
"nixcn-cms/utils"
@@ -16,8 +16,15 @@ func JWTAuth() gin.HandlerFunc {
authtoken := new(authtoken.Token)
uid, err := authtoken.HeaderVerify(auth)
if err != nil {
fmt.Println(err)
utils.HttpAbort(c, 401, "", "unauthorized")
errorCode := new(exception.Builder).
SetStatus(exception.ErrorStatusServer).
SetService(exception.MiddlewareJwtService).
SetEndpoint(exception.MiddlewareEndpoint).
SetType(exception.ErrorTypeSpecific).
SetOriginal(exception.CommonErrorUnauthorized).
Build()
utils.HttpAbort(c, 401, errorCode)
return
}