Files
mayfly-go/base/bizerror.go
meilin.huang 6f0d87c562 first
2020-09-01 10:53:51 +08:00

28 lines
530 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package base
// 业务错误
type BizError struct {
code int16
err string
}
// 错误消息
func (e *BizError) Error() string {
return e.err
}
// 错误码
func (e *BizError) Code() int16 {
return e.code
}
// 创建业务逻辑错误结构体,默认为业务逻辑错误
func NewBizErr(msg string) BizError {
return BizError{code: BizErrorCode, err: msg}
}
// 创建业务逻辑错误结构体可设置指定错误code
func NewBizErrCode(code int16, msg string) BizError {
return BizError{code: code, err: msg}
}