fix errcode
This commit is contained in:
parent
3038c6c22c
commit
820d7a5c63
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
// HTTP请求头相关错误码,起始码:1000
|
||||
var (
|
||||
AllErrors = make(map[int]string)
|
||||
ErrHeaderRequestId = NewError(1001, "Header Request-Id Not Found") // 请求ID头缺失
|
||||
ErrHeaderAuthorization = NewError(1002, "Header Authorization Not Found") // 授权头缺失
|
||||
ErrHeaderSecretKey = NewError(1003, "Header Secret-Key Not Found") // 密钥头缺失
|
||||
|
@ -81,6 +82,7 @@ var (
|
|||
// code: 错误码
|
||||
// msg: 错误消息
|
||||
func NewError(code int, msg string) error {
|
||||
AllErrors[code] = msg
|
||||
return status.New(codes.Code(code), msg).Err()
|
||||
}
|
||||
|
||||
|
@ -88,6 +90,7 @@ func NewError(code int, msg string) error {
|
|||
// code: 错误码
|
||||
// msg: 错误消息
|
||||
func ErrFatal(code int, msg string) error {
|
||||
AllErrors[code] = msg
|
||||
return status.New(codes.Code(code), msg).Err()
|
||||
}
|
||||
|
||||
|
@ -95,5 +98,6 @@ func ErrFatal(code int, msg string) error {
|
|||
// code: 错误码
|
||||
// msg: 错误消息,会自动转换为大写
|
||||
func ErrNotFound(code int, msg string) error {
|
||||
AllErrors[code] = strings.ToUpper(msg)
|
||||
return status.New(codes.Code(code), strings.ToUpper(msg)).Err()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue