Skip to content

How to intercept an error from an interceptor? #589

Answered by jhump
lalloni asked this question in Q&A
Discussion options

You must be logged in to vote

@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:

func (e errorInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc {
	return func(ctx context.Context, conn connect.StreamingHandlerConn) error {
		err := next(ctx, conn)
		if err == nil {
			return nil
		}
		if errors.Is(err, &connect.Error{}) {
			return err
		}
		return sanitize(err)
	}
}

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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lalloni
Comment options

@jhump
Comment options

Answer selected by lalloni
@lalloni
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants