You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a problem with aborting streamed responses - it turned out to be a problem with the way I did the error handling. See expressjs/express#2700 for reference. It would have helped me if the error handling guide had had a mention of the default behavior that is already included in Express. I ended up re-implementing it in my own error handler.
## The Default Error Handler
Express has some default error handling behaviour which it is worth
knowing. If you pass an error to `next` and you do not handle it in
an error handler, it will be written to the client. Including the
stack trace, which is handy for development.
If you call `next` with an error after you have started writing the
response, for instance if you encounter an error while streaming the
response to the client, Express' default error handler will close the
connection and make the request be considered failed.
So when you add a custom error handler you will want to delegate to
the default error handling mechanisms in express, when the headers
have already been sent to the client.
```jsfunctionerrorHandler(err, req, res, next) {
if (res.headersSent) {
returnnext(err);
}
res.status(500);
res.render('error', { error: err });
}
```
What are your thoughts? The above is just a rough draft, so feel free to take and modify or discard it entirely.
The text was updated successfully, but these errors were encountered:
I encountered a problem with aborting streamed responses - it turned out to be a problem with the way I did the error handling. See expressjs/express#2700 for reference. It would have helped me if the error handling guide had had a mention of the default behavior that is already included in Express. I ended up re-implementing it in my own error handler.
What are your thoughts? The above is just a rough draft, so feel free to take and modify or discard it entirely.
The text was updated successfully, but these errors were encountered: