routing-controllers
routing-controllers copied to clipboard
fix: check if headersSent
Description
Check response.headersSent
in both handleSuccess & handleError, prevents that response already sent and Express app crashed.
While I agree with this, I feel like we should somehow indicate that your response from the controller will not be delivered. Simply refusing to return your response from the controller might cause a lot of confusion and debugging. @NoNameProvided thoughts?
In my case, I'm create a middleware prevents long-run response (for example, if the API not response in 5 seconds, just send 504 then don't delivery the long-run response).
Without the check the handleSuccess / handleError will failed and crashed.
I get your point and I agree with it, my only concern is that it might cause unexpected results. We should somehow indicate (log?) that this happened. For example just adding and error.log letting the dev know that the controller result is ignored because the headers are already sent. Obviously console.log is not the perfect solution, just a low hanging fruit :)
I'm agree to improve that, how about optional warning to console.log? and the warning and opt-out.
Lets go with a warning now if the headers are already sent.
Could you please add a tests?
Could you please add a tests?
Sure. Let me check how to do that.