Skip to content

How to send error to client in streaming responses? #3042

Answered by mladedav
liss-h asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, that's not possible. You have to first send a status code (in your case most likely 200 since you're not expecting errors yet) and then you start streaming the body. At that time you can't change your mind to sending 400 instead.

Closing the connection is pretty much the only standard way to signal to the client that something has gone wrong.

If you're controlling both the client and server, you can also utilize trailers after the body to signal errors or any other metadata.

#1951 might be of some interest to you.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jplatte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants