package comm import ( "go_dreamfactory/pb" "github.com/pkg/errors" ) type CustomError struct { Code pb.ErrorCode `json:"code"` // 业务码 Message string `json:"message"` // 业务注释 } func (e *CustomError) Error() string { return e.Code.String() } func NewCustomError(code pb.ErrorCode) error { // 初次调用得用Wrap方法,进行实例化 return errors.Wrap(&CustomError{ Code: code, Message: code.String(), }, "") }