(code codes.Code, err error, details ...protoadapt.MessageV1)
| 74 | } |
| 75 | |
| 76 | func 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 |
no test coverage detected