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 would like to detect a bug in my express 5 app where a request has been handled by express, but it somehow did not send a response to the client. This results in leaving the client hanging and is difficult to debug.
A typical scenario in which this occurs is when a router code does something async in a promise, but you forgot to return this promise in the router. In this case, when the promise gets rejected, express will not catch it and send a error message to the client.
What I need is a hook or type of middleware (postware?) that always runs after express is done with the request, including waiting for a promise returned by the router to get settled and running the error handler on rejection. Once all this has completed I want to run a final check if anything has actually been sent to the client.
I understand this does not work for express applications in general, because it requires routers always return the promise that will sending a response, which express does not require. But I think it is good practice and it will make it possible to use such a postware handler.
This discussion was converted from issue #6165 on November 12, 2024 11:55.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would like to detect a bug in my express 5 app where a request has been handled by express, but it somehow did not send a response to the client. This results in leaving the client hanging and is difficult to debug.
A typical scenario in which this occurs is when a router code does something async in a promise, but you forgot to
return
this promise in the router. In this case, when the promise gets rejected, express will not catch it and send a error message to the client.What I need is a hook or type of middleware (postware?) that always runs after express is done with the request, including waiting for a promise returned by the router to get settled and running the error handler on rejection. Once all this has completed I want to run a final check if anything has actually been sent to the client.
I understand this does not work for express applications in general, because it requires routers always
return
the promise that will sending a response, which express does not require. But I think it is good practice and it will make it possible to use such a postware handler.Beta Was this translation helpful? Give feedback.
All reactions