MCPcopy
hub / github.com/connectrpc/connect-go / grpcErrorToTrailer

Function grpcErrorToTrailer

protocol_grpc.go:841–868  ·  view source on GitHub ↗
(trailer http.Header, protobuf Codec, err error)

Source from the content-addressed store, hash-verified

839}
840
841func grpcErrorToTrailer(trailer http.Header, protobuf Codec, err error) {
842 if err == nil {
843 setHeaderCanonical(trailer, grpcHeaderStatus, "0") // zero is the gRPC OK status
844 return
845 }
846 if connectErr, ok := asError(err); ok && !connectErr.wireErr {
847 mergeNonProtocolHeaders(trailer, connectErr.meta)
848 }
849 var (
850 status = grpcStatusForError(err)
851 code = status.GetCode()
852 message = status.GetMessage()
853 bin []byte
854 )
855 if len(status.Details) > 0 {
856 var binErr error
857 bin, binErr = protobuf.Marshal(status)
858 if binErr != nil {
859 code = int32(CodeInternal)
860 message = fmt.Sprintf("marshal protobuf status: %v", binErr)
861 }
862 }
863 setHeaderCanonical(trailer, grpcHeaderStatus, strconv.Itoa(int(code)))
864 setHeaderCanonical(trailer, grpcHeaderMessage, grpcPercentEncode(message))
865 if len(bin) > 0 {
866 setHeaderCanonical(trailer, grpcHeaderDetails, EncodeBinaryHeader(bin))
867 }
868}
869
870func grpcStatusForError(err error) *statusv1.Status {
871 status := &statusv1.Status{

Callers 3

CloseMethod · 0.85
writeGRPCMethod · 0.85
writeGRPCWebMethod · 0.85

Calls 9

setHeaderCanonicalFunction · 0.85
asErrorFunction · 0.85
mergeNonProtocolHeadersFunction · 0.85
grpcStatusForErrorFunction · 0.85
grpcPercentEncodeFunction · 0.85
EncodeBinaryHeaderFunction · 0.85
GetMessageMethod · 0.80
MarshalMethod · 0.65
GetCodeMethod · 0.45

Tested by

no test coverage detected