MCPcopy
hub / github.com/grpc/grpc-go / FromContextError

Function FromContextError

status/status.go:151–162  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
151func 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}

Callers 5

processUnaryRPCMethod · 0.92
processStreamingRPCMethod · 0.92
shouldRetryMethod · 0.92
waitForResolvedAddrsMethod · 0.92
TestFromContextErrorMethod · 0.85

Calls 3

IsMethod · 0.80
NewFunction · 0.70
ErrorMethod · 0.65

Tested by 1

TestFromContextErrorMethod · 0.68