Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communicate streamed response errors to clients which don't support HTTP Trailers #929

Open
alxndrsn opened this issue Jul 15, 2023 · 0 comments

Comments

@alxndrsn
Copy link
Contributor

When there is an error in a streamed response, an HTTP trailer is added at:

const streamErrorHandler = (response, next) => (err) => {
response.addTrailers({ Status: 'Error' }); // TODO: improve response content.
response.end();
next(err);
};

From node docs:

Trailers will only be emitted if chunked encoding is used for the response; if it is not (e.g. if the request was HTTP/1.0), they will be silently discarded.

HTTP requires the Trailer header to be sent in order to emit trailers,...
-https://nodejs.org/docs/latest-v16.x/api/http.html#responseaddtrailersheaders

There is a unit test covering the error handler:

trailers.should.eql({ Status: 'Error' });

It's unclear if the trailers are actually written in practice:

  • the test is just checking that response.addTrailers() was called
  • currently "69%" of browsers support trailers (https://caniuse.com/?search=trailer)
  • the Trailer header is not being explicitly added to the response
  • "chunked encoding" is not being explicitly used for the response (maybe chunked is enabled by default?)

Are the trailers written in normal use? How do they affects e.g. interactive CSV download in a browser?

If the trailers are not written, or a failure is not communicated clearly to users, there might be alternative/additional ways to communicate an error to a user. These might include:

  • .csv: e.g. write a final line --- ERROR DOWNLOADING CSV DATA ---
  • .zip: e.g. deliberately corrupt the file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant