I'm trying to understand how to handle nodejs timeout on a get call.
I have a page which requires a long execution time before being rendered.
I would like to set a timeout, and if we hit the timeout, I would like to abort the request, and redirect the user to a timeout page.
I've done this in my route.js file :
app.get('/exec', isLoggedIn, function(req, res) {
var defaultTimeout = 180000;
res.connection.setTimeout(defaultTimeout, function(t) {
console.log("TIMED OUT !");
res.render('exec-timeout.ejs', {
user : req.user
});
});
});
But it doesn't work... It hits the timeout, it displays the "TIMED OUT" message in the console, but it doesn't redirect me to the exec-timeout page, it just keeps trying to run the execution and hits the timeout again...
How can I abort the request on timeout, and render to the page ?
Thanks a lot.