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("NotFoundConf Err module:%s ,file:%s,id:%v", moduleName, filename, id) } // 执行外部模块异常 func NewExternalModuleErr(moduleName string, methodname string, parameter ...interface{}) error { return fmt.Errorf("ExternalModule Err module:%s ,file:%s,parameter:%v", moduleName, methodname, parameter) }