FG
๐ŸŒ Web & Full-Stack

defaut error handler (finalhandler) should not prevent the response being sent

Freshabout 10 years ago
Mar 14, 20260 views
Confidence Score88%
88%

Problem

Or else there should be an option to provide a custom made final handler. Why: I use 2 error handlers in my app : one that logs the error in our database, and one that returns a 500 to the client, with an particular error message. If for any reason I have two bits of async code that both rise an error, the app just throws the 2nd error to stderr and don't return anything (not even the first 500) to the client. So the bug is : first error calls next(err) two times and traverses my 2 error handlers. But when next(err2) is called on the 2nd error, we are already beind my 2 error handlers in the route stack, and the finalHandler is called. This happens often in a rest api style app (which is our case) : some route ask to do some operation on multiple business objects, we do all operations in, for instance, a "async.parallel", but due to a legitimate problems, some of those operations return an error. In such case, I would like to configure my app to do : log all the errors to the database send to the client a proper error 500 with a custom message corresponding to the first error that occured (there is a good chance the next errors will have the same cause and message, but even if not, this is still the desired behaviour) I read an argument saying that if we are sending a "normal" response to the client, and an error occur, it's preferable to stop everything, that to finish sending the response to the client and making it belive that everything is OK. I would argue that :

Error Output

error handlers in my app : one that logs the error in our database, and one that returns a 500 to the client, with an particular error message.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: defaut error handler (finalhandler) should not prevent the response being sent

Low Risk

No interest at all for this problem ? I thought I had described it pretty thouroughly, even describing which part of the code has the problem... This is really a big problem guys, in a production environement, it's unthinkable to not catch errors properly when they are in an asynchronous call (which is kind the point of Node)

84

Trust Score

1 verification

100% success
  1. 1

    No interest at all for this problem ? I thought I had described it pretty thouro

    No interest at all for this problem ? I thought I had described it pretty thouroughly, even describing which part of the code has the problem...

  2. 2

    This is really a big problem guys, in a production environement, it's unthinkabl

    This is really a big problem guys, in a production environement, it's unthinkable to not catch errors properly when they are in an asynchronous call (which is kind the point of Node)

Validation

Resolved in expressjs/express GitHub issue #2793. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

expressnode.jsapi5.x