I would like to have custome response time-out, so that I am trying to send the response from setTimeout
callback if the processing time exceeds certain interval.
In the following example, I set 20ms as time-out period within which services.getReport()
has to be processed otherwise the API has to send response as response_timed_out
.
The following code works fine but it throws exception like
Cannot set headers after they are sent to the client
router.post("/getReport", (req, res) => {
setTimeout(() => {
res.send({ status:503, msg: "response_timed_out" });
}, 20);
services.getReport(req, res);
});