46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package errorcode
|
|
|
|
var (
|
|
Success = &BusinessErr{code: "0000", message: "成功"}
|
|
ParamError = &BusinessErr{code: "0001", message: "参数错误"}
|
|
NotFoundError = &BusinessErr{code: "0004", message: "请求地址未找到"}
|
|
SystemError = &BusinessErr{code: "0005", message: "系统错误"}
|
|
|
|
SupplierNotFound = &BusinessErr{code: "0006", message: "供应商不存在"}
|
|
SessionNotFound = &BusinessErr{code: "0007", message: "未找到会话信息"}
|
|
AuthNotFound = &BusinessErr{code: "0008", message: "身份验证失败"}
|
|
KeyNotFound = &BusinessErr{code: "0009", message: "身份验证失败"}
|
|
SysNotFound = &BusinessErr{code: "0010", message: "未找到系统信息"}
|
|
InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"}
|
|
)
|
|
|
|
const (
|
|
InvalidParamCode = "0008"
|
|
)
|
|
|
|
type BusinessErr struct {
|
|
code string
|
|
message string
|
|
}
|
|
|
|
func (e *BusinessErr) Error() string {
|
|
return e.message
|
|
}
|
|
func (e *BusinessErr) Code() string {
|
|
return e.code
|
|
}
|
|
|
|
func (e *BusinessErr) Is(target error) bool {
|
|
_, ok := target.(*BusinessErr)
|
|
return ok
|
|
}
|
|
|
|
// CustomErr 自定义错误
|
|
func NewBusinessErr(code string, message string) *BusinessErr {
|
|
return &BusinessErr{code: code, message: message}
|
|
}
|
|
|
|
func (e *BusinessErr) Wrap(err error) *BusinessErr {
|
|
return NewBusinessErr(e.code, err.Error())
|
|
}
|