MCPcopy Index your code
hub / github.com/PeerDB-io/peerdb / convertToStatus

Function convertToStatus

flow/cmd/api_error.go:76–89  ·  view source on GitHub ↗
(code codes.Code, err error, details ...protoadapt.MessageV1)

Source from the content-addressed store, hash-verified

74}
75
76func convertToStatus(code codes.Code, err error, details ...protoadapt.MessageV1) *status.Status {
77 errorStatus := status.New(code, err.Error())
78 if len(details) == 0 {
79 return errorStatus
80 }
81 richStatus, err := errorStatus.WithDetails(details...)
82 if err != nil {
83 // This cannot happen because we control all calls to convertToStatus and only pass code != OK and valid proto details
84 slog.Error("Failed to convert to grpc proto error", slog.Any("error", err)) //nolint:sloglint // No context in conversion helper
85 return errorStatus
86 }
87
88 return richStatus
89}
90
91// AsAPIError converts an error to APIError if it's a gRPC status error,
92// otherwise wraps it as an Internal error

Callers 7

NewInternalApiErrorFunction · 0.85
NewUnavailableApiErrorFunction · 0.85
NewUnimplementedApiErrorFunction · 0.85
NewAlreadyExistsApiErrorFunction · 0.85
NewNotFoundApiErrorFunction · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected