feat 错误码
This commit is contained in:
@@ -27,7 +27,6 @@ func NewGrpcConnection(sid string, address string) (*GrpcConnection, error) {
|
||||
PermitWithoutStream: true,
|
||||
},
|
||||
),
|
||||
//grpc.WithStatsHandler(&StatsHandler{}),
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("create grpc err: %v, sid: %v, addr: %v", err, sid, address)
|
||||
|
||||
@@ -20,7 +20,6 @@ func NewGrpcConnection(target string) (*grpc.ClientConn, error) {
|
||||
PermitWithoutStream: true,
|
||||
},
|
||||
),
|
||||
//grpc.WithStatsHandler(&StatsHandler{}),
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("create grpc err: %v, target: %v", err, target)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user