@@ -55,6 +55,7 @@ import (
5555 "google.golang.org/grpc"
5656 "google.golang.org/grpc/status"
5757 "google.golang.org/protobuf/proto"
58+ "google.golang.org/protobuf/protoadapt"
5859)
5960
6061// VisitPayloadsContext provides Payload context for visitor functions.
@@ -114,6 +115,7 @@ func NewPayloadVisitorInterceptor(options PayloadVisitorInterceptorOptions) (grp
114115 // user provided payloads can sometimes end up in the status details of
115116 // gRPC errors, make sure to visit those as well
116117 newStatus := status.New(stat.Code(), stat.Message())
118+ var newDetails []protoadapt.MessageV1
117119 for _, detail := range stat.Details() {
118120 detailAny, ok := detail.(*anypb.Any)
119121 if ok && ({{ range $i, $name := .GrpcPayload }}{{ if $i }} || {{ end }}detailAny.MessageName() == "{{$name}}"{{ end }}) {
@@ -122,10 +124,11 @@ func NewPayloadVisitorInterceptor(options PayloadVisitorInterceptorOptions) (grp
122124 return err
123125 }
124126 }
125- newStatus, err = newStatus.WithDetails(detailAny)
126- if err != nil {
127- return err
128- }
127+ newDetails = append(newDetails, detailAny)
128+ }
129+ newStatus, err = newStatus.WithDetails(newDetails...)
130+ if err != nil {
131+ return err
129132 }
130133 return newStatus.Err()
131134 }
@@ -194,6 +197,7 @@ func NewFailureVisitorInterceptor(options FailureVisitorInterceptorOptions) (grp
194197 // user provided payloads can sometimes end up in the status details of
195198 // gRPC errors, make sure to visit those as well
196199 newStatus := status.New(stat.Code(), stat.Message())
200+ var newDetails []protoadapt.MessageV1
197201 for _, detail := range stat.Details() {
198202 detailAny, ok := detail.(*anypb.Any)
199203 if ok && ({{ range $i, $name := .GrpcFailure }}{{ if $i }} || {{ end }}detailAny.MessageName() == "{{$name}}"{{ end }}) {
@@ -202,10 +206,11 @@ func NewFailureVisitorInterceptor(options FailureVisitorInterceptorOptions) (grp
202206 return err
203207 }
204208 }
205- newStatus, err = newStatus.WithDetails(detailAny)
206- if err != nil {
207- return err
208- }
209+ newDetails = append(newDetails, detailAny)
210+ }
211+ newStatus, err = newStatus.WithDetails(newDetails...)
212+ if err != nil {
213+ return err
209214 }
210215 return newStatus.Err()
211216 }
0 commit comments