diff --git a/dto/error.go b/dto/error.go index 907c478..7931a83 100644 --- a/dto/error.go +++ b/dto/error.go @@ -12,4 +12,6 @@ const ( // DataOperationError 数据操作错误(增删改查操作出了意料之外的错误都算) DataOperationError = 2002 ArgumentParseError = 3000 + + NoAuthOperationError = 4001 ) diff --git a/middleware/auth.go b/middleware/auth.go index 27352a3..0da5a40 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -1,7 +1,6 @@ package middleware import ( - "net/http" "strings" "github.com/gin-gonic/gin" @@ -39,7 +38,7 @@ func permissionMiddleware() gin.HandlerFunc { if isVaild { // 用户有权限 c.Next() } else { - c.JSON(http.StatusUnauthorized, "无权限访问") + panic(dto.ErrorDto{Code: dto.NoAuthOperationError, Message: "无权限操作"}) } } } diff --git a/service/publishedGi.go b/service/publishedGi.go index bdd330c..ba1e2be 100644 --- a/service/publishedGi.go +++ b/service/publishedGi.go @@ -57,7 +57,7 @@ func PublishFormDraft(req *publishedGi.PublishReqDto, user *model.User) { } //需要删除的同名数据 oldData, _ := dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Find() - if oldData != nil && len(oldData) > 0 { + if len(oldData) > 0 { // 逻辑删除 dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).UpdateColumn(dbquery.PublishedGi.Status, 0) for _, v := range oldData {