48 lines
1.2 KiB
Go
48 lines
1.2 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: "供应商不存在"}
|
|
SupplierApiError = &BusinessErr{code: "0007", 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())
|
|
}
|
|
|
|
func SupplierApiErrorDiy(message string) *BusinessErr {
|
|
return &BusinessErr{code: SupplierApiError.code, message: message}
|
|
}
|