go_dreamfactory/comm/error.go
2023-07-05 18:17:21 +08:00

36 lines
915 B
Go
Raw Permalink 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 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)
}