Skip to content

Commit

Permalink
Merge pull request #353 from iamqizhao/master
Browse files Browse the repository at this point in the history
add accessor for the error desc of rpcError
  • Loading branch information
iamqizhao committed Sep 22, 2015
2 parents 64295ba + 3913070 commit 4d81fd3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4d81fd3

Please sign in to comment.