-
We are trying to write an interceptor to detect errors that are not The above works well for unary methods, but we can't find a way to intercept errors in the streaming methods case via a
type StreamingHandlerConn interface {
Spec() Spec
Peer() Peer
Receive(any) error
RequestHeader() http.Header
Send(any) error
ResponseHeader() http.Header
ResponseTrailer() http.Header
} And there are no apparent method/s to override to intercept errors (as returned from handlers) and transforming them to other errors forms (e.g. a Any clue would be very appreciated. As context information, this is what we are using for unary methods: func (e errorInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) {
r, err := next(ctx, request)
if err == nil {
return r, nil
}
if errors.Is(err, &connect.Error{}) {
return nil, err
}
return nil, sanitize(err)
}
}
func sanitize(err error) *connect.Error {
// log details and return sanitized error
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You'd implement |
Beta Was this translation helpful? Give feedback.
@lalloni, I don't quite follow why you can't use the same approach as for the unary case. I think it would be as simple as this:
If that is not sufficient, can you elaborate on why not?
Wrapping the stream connection is only necessary from the client side, as that is the way that the client will observe the errors, in particular from the
Receive
method.