FromContextError converts a context error or wrapped context error into a Status. It returns a Status with codes.OK if err is nil, or a Status with codes.Unknown if err is non-nil and not a context error.
(err error)
| 149 | // Status. It returns a Status with codes.OK if err is nil, or a Status with |
| 150 | // codes.Unknown if err is non-nil and not a context error. |
| 151 | func FromContextError(err error) *Status { |
| 152 | if err == nil { |
| 153 | return nil |
| 154 | } |
| 155 | if errors.Is(err, context.DeadlineExceeded) { |
| 156 | return New(codes.DeadlineExceeded, err.Error()) |
| 157 | } |
| 158 | if errors.Is(err, context.Canceled) { |
| 159 | return New(codes.Canceled, err.Error()) |
| 160 | } |
| 161 | return New(codes.Unknown, err.Error()) |
| 162 | } |