15 lines
423 B

10 years ago
// handle time out errors
function middleware(err, req, res, next) {
res.header('Cache-Control','no-cache');
var error = (err && err.message) ? err.message : err;
if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){
10 years ago
res.status(408);
res.json({ error: typeof error === 'string' ? error : 'request timeout' });
10 years ago
} else {
next(err);
}
10 years ago
}
module.exports = middleware;