dreamfactory_cmd/comm/error.go
2023-06-09 21:58:02 +08:00

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