-
SummaryHello, Imagine something like this: async fn handle_request(...) -> impl IntoResponse {
let stream: impl Stream<Item = io::Result<Bytes>> = /* some stream that produces an error */;
Body::from_stream(stream)
} Now, this does not exactly do what I expected: In the case the stream produces an Is there any way to send the error to the client instead? Note: Our usecase is a triplestore with Thanks in advance 🙂 axum version0.7.7 atm, but we can upgrade to a newer one if required |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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. |
Beta Was this translation helpful? Give feedback.
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.