Browse Source

big fix - err is of type string if there is an error within express app - its of type object (with .message being string) in case of errors messages from the ES cluster

pull/169/head
Harish Krishna 10 years ago
parent
commit
ae4e75784f
  1. 6
      middleware/408.js
  2. 3
      middleware/500.js

6
middleware/408.js

@ -2,9 +2,11 @@
// handle time out errors // handle time out errors
function middleware(err, req, res, next) { function middleware(err, req, res, next) {
res.header('Cache-Control','no-cache'); 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.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 { } else {
next(err); next(err);
} }

3
middleware/500.js

@ -4,8 +4,9 @@ var logger = require( 'pelias-logger' ).get( 'middleware-500' );
function middleware(err, req, res, next) { function middleware(err, req, res, next) {
logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack ); logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack );
res.header('Cache-Control','no-cache'); res.header('Cache-Control','no-cache');
var error = err.message ? err.message : err;
if( res.statusCode < 400 ){ res.status(500); } 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; module.exports = middleware;

Loading…
Cancel
Save