diff --git a/app.js b/app.js index 869628de..933b7093 100644 --- a/app.js +++ b/app.js @@ -52,6 +52,7 @@ app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined /** ----------------------- error middleware ----------------------- **/ app.use( require('./middleware/404') ); +app.use( require('./middleware/408') ); app.use( require('./middleware/500') ); module.exports = app; \ No newline at end of file diff --git a/middleware/408.js b/middleware/408.js new file mode 100644 index 00000000..f0edfd59 --- /dev/null +++ b/middleware/408.js @@ -0,0 +1,9 @@ + +// handle time out errors +function middleware(err, req, res, next) { + res.header('Cache-Control','no-cache'); + if( res.statusCode === 408 ){ res.status(408); } + res.json({ error: typeof err === 'string' ? err : 'request time out' }); +} + +module.exports = middleware; \ No newline at end of file