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 }