MCPcopy
hub / github.com/grafana/dskit / ErrorToStatus

Function ErrorToStatus

grpcutil/status.go:24–38  ·  view source on GitHub ↗

ErrorToStatus returns a *github.com/gogo/status.Status representation of err. - If err implements the method `GRPCStatus() *google.golang.org/grpc/status.Status` and `GRPCStatus()` does not return nil, or if err wraps a type satisfying this, Status from `GRPCStatus()` is converted to gogo Status, a

(err error)

Source from the content-addressed store, hash-verified

22// - Otherwise, err is an error not compatible with this function. In this
23// case, a nil Status is returned and ok is false.
24func ErrorToStatus(err error) (*status.Status, bool) {
25 if err == nil {
26 return nil, false
27 }
28 type grpcStatus interface{ GRPCStatus() *grpcstatus.Status }
29 var gs grpcStatus
30 if errors.As(err, &gs) {
31 st := gs.GRPCStatus()
32 if st == nil {
33 return nil, false
34 }
35 return status.FromGRPCStatus(st), true
36 }
37 return nil, false
38}
39
40// ErrorToStatusCode extracts gRPC status code from error and returns it.
41//

Callers 3

HTTPResponseFromErrorFunction · 0.92
TestErrorToStatusFunction · 0.85

Calls 1

GRPCStatusMethod · 0.95

Tested by 1

TestErrorToStatusFunction · 0.68