From b3f85ebc17d94e564eefc1132c6c6b4bfa486487 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Mon, 20 Jul 2015 16:41:03 -0400 Subject: [PATCH] err & err.message instead of err.message --- middleware/408.js | 2 +- middleware/500.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/middleware/408.js b/middleware/408.js index 9688af2e..92dc9723 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,7 +2,7 @@ // handle time out errors function middleware(err, req, res, next) { res.header('Cache-Control','no-cache'); - var error = err.message ? err.message : err; + var error = (err && err.message) ? err.message : err; if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ res.status(408); diff --git a/middleware/500.js b/middleware/500.js index 373ef958..cc3f8325 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -4,7 +4,8 @@ var logger = require( 'pelias-logger' ).get( 'middleware-500' ); function middleware(err, req, res, next) { logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack ); res.header('Cache-Control','no-cache'); - var error = err.message ? err.message : err; + var error = (err && err.message) ? err.message : err; + if( res.statusCode < 400 ){ res.status(500); } res.json({ error: typeof error === 'string' ? error : 'internal server error' }); }