Hi there,
I have a case where I need to setup headers dynamically, e.g.:
response.setHeader("Expires", dateFormat.format("ddd, DD MMM YYYY HH:mm:ss") + " GMT");
If I do that using response object @Res() response: any, I always get error:
(node:29688) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:470:11)
at ServerResponse.header (webpack:///./node_modules/express/lib/response.js?:771:10)
at eval (webpack:///./node_modules/routing-controllers/driver/express/ExpressDriver.js?:364:32)
at Array.forEach (<anonymous>)
at ExpressDriver.handleError (webpack:///./node_modules/routing-controllers/driver/express/ExpressDriver.js?:363:45)
at eval (webpack:///./node_modules/routing-controllers/RoutingControllers.js?:104:33)
at process._tickCallback (internal/process/next_tick.js:68:7)
Please advise how to handle this kind of scenario.
@azaslonov which routing-controllers version are you using? We fixed that in the 0.9.0-alpha.2 pre-release.
Can you try with the latest release candidate, please?
Hi @jotamorais, thanks for the quick response. I use "routing-controllers": "^0.9.0-alpha.3"
Did you also disable the defaultErrorHandler in the RoutingControllersOptions?
Indeed, I did not. I missed that part in the docs. Thanks a lot!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.