add accessor for the error desc of rpcError
This commit is contained in:
12
rpc_util.go
12
rpc_util.go
@ -217,6 +217,18 @@ func Code(err error) codes.Code {
|
||||
return codes.Unknown
|
||||
}
|
||||
|
||||
// Desc returns the error description of err if it was produced by the rpc system.
|
||||
// Otherwise, it returns err.Error() or empty string when err is nil.
|
||||
func Desc(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
if e, ok := err.(rpcError); ok {
|
||||
return e.desc
|
||||
}
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
// Errorf returns an error containing an error code and a description;
|
||||
// Errorf returns nil if c is OK.
|
||||
func Errorf(c codes.Code, format string, a ...interface{}) error {
|
||||
|
Reference in New Issue
Block a user