package comm import ( "fmt" "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.ToString(), }, "") } // 创建配置表错误对象 func NewNotFoundConfErr(moduleName string, filename string, id interface{}) error { return fmt.Errorf("服务端配置未找到!模块:%s ,配置文件:%s,目标数据:%v", moduleName, filename, id) } // 执行外部模块异常 func NewExternalModuleErr(moduleName string, methodname string, parameter ...interface{}) error { return fmt.Errorf("执行外部模块错误 模块:%s ,配置文件:%s,目标数据:%v", moduleName, methodname, parameter) }