GetGrpcCode retrieves the gRPC code from a stack of causes.
(err error)
| 70 | |
| 71 | // GetGrpcCode retrieves the gRPC code from a stack of causes. |
| 72 | func GetGrpcCode(err error) codes.Code { |
| 73 | if err == nil { |
| 74 | return codes.OK |
| 75 | } |
| 76 | if v, ok := markers.If(err, func(err error) (interface{}, bool) { |
| 77 | if w, ok := err.(*withGrpcCode); ok { |
| 78 | return w.code, true |
| 79 | } |
| 80 | return nil, false |
| 81 | }); ok { |
| 82 | return v.(codes.Code) |
| 83 | } |
| 84 | return codes.Unknown |
| 85 | } |
| 86 | |
| 87 | // it's an error. |
| 88 | func (w *withGrpcCode) Error() string { return w.cause.Error() } |