diff --git a/middleware/408.js b/middleware/408.js index 2b2a7b8a..9688af2e 100644 --- a/middleware/408.js +++ b/middleware/408.js @@ -2,9 +2,11 @@ // handle time out errors function middleware(err, req, res, next) { res.header('Cache-Control','no-cache'); - if( res.statusCode === 408 || (err.message.toLowerCase().indexOf('request timeout') !== -1) ){ + var error = err.message ? err.message : err; + + if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ res.status(408); - res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' }); + res.json({ error: error === 'string' ? error : 'request time out' }); } else { next(err); } diff --git a/middleware/500.js b/middleware/500.js index 9f274e23..373ef958 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -4,8 +4,9 @@ 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; if( res.statusCode < 400 ){ res.status(500); } - res.json({ error: err && typeof err.message === 'string' ? err.message : 'internal server error' }); + res.json({ error: typeof error === 'string' ? error : 'internal server error' }); } module.exports = middleware;