I'm using NodeJS Express
I have set a maximum request timeout of 25 seconds. When the timer exceeds the 25 seconds It needs to send a response (status 500). At this moment I'm getting errors that the connection is closed without a response, how can I improve my code?
Note: the request timeout could just be an image, I still want full the page to load, only without that particular image (request).
Below you can find the code I'm currently using
const haltOnTimedout = (req, res, next) => {
if (!req.timedout) {
next();
}else {
res.status(500)
}
}
app.use(timeout('25s'))
app.use(bodyParser.json({ extended: true }))
app.use(haltOnTimedout)