From 793182148a96fbbc874e1199696bbe91baba2d30 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 14 Jul 2015 14:01:59 -0400 Subject: [PATCH] middleware fix --- middleware/408.js | 8 ++++++-- middleware/500.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/middleware/408.js b/middleware/408.js index f0edfd59..fd577fb2 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,8 +2,12 @@ // 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' }); + if( res.statusCode === 408 ){ + res.status(408); + res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' }); + } else { + next(err); + } } module.exports = middleware; \ No newline at end of file diff --git a/middleware/500.js b/middleware/500.js index ecd2ee1d..9f274e23 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -5,7 +5,7 @@ function middleware(err, req, res, next) { logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack ); res.header('Cache-Control','no-cache'); if( res.statusCode < 400 ){ res.status(500); } - res.json({ error: typeof err === 'string' ? err : 'internal server error' }); + res.json({ error: err && typeof err.message === 'string' ? err.message : 'internal server error' }); } module.exports = middleware;