parent
ea15293e22
commit
5f4db21c11
@ -0,0 +1,11 @@
|
||||
package nstatus
|
||||
|
||||
// NewBizErr 构建业务错误
|
||||
func NewBizErr(code int, message string) error {
|
||||
return NewResult(code, message, BizErr)
|
||||
}
|
||||
|
||||
// NewBizErrNoMsg 构建业务错误,空错误消息
|
||||
func NewBizErrNoMsg(code int) error {
|
||||
return NewBizErr(code, "")
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package nstatus
|
||||
|
||||
import (
|
||||
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
|
||||
)
|
||||
|
||||
// ConvertErr is a convenience function which removes the need to handle the
|
||||
// boolean return value from FromError.
|
||||
func ConvertErr(err error) *Result {
|
||||
s, ok := FromError(err)
|
||||
if !ok {
|
||||
// 尝试grpc
|
||||
return WrapGrpcErr(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// FromError returns a Status representation of err.
|
||||
//
|
||||
// - If err was produced by this package *Result`, the appropriate Result is returned.
|
||||
// - If err is nil, a nil is returned.
|
||||
//
|
||||
// - Otherwise, err is an error not compatible with this package. In this
|
||||
// case, a *Result is returned with code.StatusUnknown and err's Error() message,
|
||||
// and ok is false.
|
||||
func FromError(err error) (s *Result, ok bool) {
|
||||
if err == nil {
|
||||
return nil, false
|
||||
}
|
||||
if se, ok := err.(*Result); ok {
|
||||
return se, true
|
||||
}
|
||||
return NewResult(code.StatusUnknown, err.Error()), false
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package nstatus
|
||||
|
||||
// ConvertErr is a convenience function which removes the need to handle the
|
||||
// boolean return value from FromError.
|
||||
func ConvertErr(err error) *Result {
|
||||
s, ok := FromError(err)
|
||||
if !ok {
|
||||
// 尝试grpc
|
||||
return WrapGrpcErr(err)
|
||||
}
|
||||
return s
|
||||
}
|
Loading…
Reference in New Issue