feat 错误码

This commit is contained in:
2026-01-14 14:21:41 +08:00
parent 6aefdaf650
commit 1c90e21050
4 changed files with 14 additions and 14 deletions

View File

@@ -7,14 +7,16 @@ import (
)
var (
OK = NewCode(0, "OK")
Failed = NewCode(1, "Failed")
TokenInvalid = NewCode(2, "Token无效")
ParamError = NewCode(1001, "参数错误")
NameEmpty = NewCode(1002, "名称不能为空")
NameDuplicate = NewCode(1003, "名称或编号不能重复")
ListEmpty = NewCode(1004, "列表不能为空")
RepeatCommit = NewCode(1005, "请勿重复提交")
OK = NewCode(0, "OK")
Failed = NewCode(1, "Failed")
TokenInvalid = NewCode(2, "Token Invalid")
MethodNotAllowed = NewCode(3, "Method Not Allowed")
NotFound = NewCode(4, "Not Found")
ParamError = NewCode(1001, "参数错误")
NameEmpty = NewCode(1002, "名称不能为空")
NameDuplicate = NewCode(1003, "名称或编号不能重复")
ListEmpty = NewCode(1004, "列表不能为空")
RepeatCommit = NewCode(1005, "请勿重复提交")
)
type Code struct {

View File

@@ -35,13 +35,13 @@ func JsonBadRequest(c *gin.Context) {
}
func JsonMethodNotAllowed(c *gin.Context) {
c.JSON(http.StatusMethodNotAllowed, Error(NewCode(Failed.Code(), "Method Not Allowed")))
c.JSON(http.StatusMethodNotAllowed, Error(MethodNotAllowed))
}
func JsonNotFound(c *gin.Context) {
c.JSON(http.StatusNotFound, Error(NewCode(Failed.Code(), "Endpoint Not Found")))
c.JSON(http.StatusNotFound, Error(NotFound))
}
func AbortUnauthorized(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusUnauthorized, Error(NewCode(Failed.Code(), "Invalid Authorization")))
func JsonUnauthorized(c *gin.Context) {
c.JSON(http.StatusUnauthorized, Error(TokenInvalid))
}