func NewCode(code int, text string) error
func NewCodef(code int, format string, args ...interface{}) error
func NewCodeSkip(code, skip int, text string) error
func NewCodeSkipf(code, skip int, format string, args ...interface{}) error
func WrapCode(code int, err error, text string) error
func WrapCodef(code int, err error, format string, args ...interface{}) error
3 Comments
xushushun
由于缺乏经验导致所有的错误一并返回给前端了,让客户看到了不应该看的错误信息.正确的业务中定义错误是不是应该增加错误码,然后controller中根据错误码来判断是否输出到前端.或者还有其它更佳方案.
郭强
可以通过拦截器/中间件来实现返回数据过滤,比如不带错误码的错误就不返回给前端而使用通用的错误。
xushushun
明白了 谢谢