HTTPResponseFromError converts a grpc error into an HTTP response
(err error)
| 145 | |
| 146 | // HTTPResponseFromError converts a grpc error into an HTTP response |
| 147 | func HTTPResponseFromError(err error) (*HTTPResponse, bool) { |
| 148 | s, ok := grpcutil.ErrorToStatus(err) |
| 149 | if !ok { |
| 150 | return nil, false |
| 151 | } |
| 152 | |
| 153 | status := s.Proto() |
| 154 | if len(status.Details) != 1 { |
| 155 | return nil, false |
| 156 | } |
| 157 | |
| 158 | var resp HTTPResponse |
| 159 | if err := types.UnmarshalAny(status.Details[0], &resp); err != nil { |
| 160 | level.Error(log.Global()).Log("msg", "got error containing non-response", "err", err) |
| 161 | return nil, false |
| 162 | } |
| 163 | |
| 164 | return &resp, true |
| 165 | } |