From 60c06194980d1492823012a1575a4440cc09c9da Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 13 Jul 2015 17:10:21 -0400 Subject: [PATCH] adding 408.js --- app.js | 1 + middleware/408.js | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 middleware/408.js 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