You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
480 B

var logger = require( 'pelias-logger' ).get( 'middleware-500' );
10 years ago
// handle application errors
function middleware(err, req, res, next) {
logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack );
10 years ago
res.header('Cache-Control','no-cache');
var error = err.message ? err.message : err;
10 years ago
if( res.statusCode < 400 ){ res.status(500); }
9 years ago
res.json({ error: err && typeof err.message === 'string' ? err.message : 'internal server error' });
10 years ago
}
module.exports = middleware;