package errorx import ( "fmt" "go-micro.dev/v4/errors" "gomicro-base/common/validate" ) const ( DefaultError = 500 ParamsError = 400 ) type ResponseError struct { Code int `json:"code"` Msg string `json:"msg"` } var _ error = &ResponseError{} func (c *ResponseError) Error() string { return fmt.Sprintf("[%d]%s", c.Code, c.Msg) } func NewMicroError(detail string, code ...int) error { var c = DefaultError if len(code) > 0 { c = code[0] } return &errors.Error{ Code: int32(c), Detail: detail, Status: "操作失败", } } func NewParamsError(err error) error { return &errors.Error{ Code: int32(ParamsError), Detail: validate.TransError(err), Status: "参数不正确", } }