mirror of https://github.com/pelias/api.git
Julian Simioni
8 years ago
committed by
GitHub
8 changed files with 44 additions and 17 deletions
@ -1,13 +1,19 @@ |
|||||||
var logger = require( 'pelias-logger' ).get( 'middleware-500' ); |
var check = require('check-types'), |
||||||
|
logger = require( 'pelias-logger' ).get( 'api' ); |
||||||
|
|
||||||
// handle application errors
|
// handle application errors
|
||||||
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','public'); |
|
||||||
var error = (err && err.message) ? err.message : err; |
|
||||||
|
|
||||||
if( res.statusCode < 400 ){ res.status(500); } |
if( res.statusCode < 400 ){ |
||||||
res.json({ error: typeof error === 'string' ? error : 'internal server error' }); |
logger.info( 'status code changed from', res.statusCode, 'to 500' ); |
||||||
|
res.status(500); |
||||||
|
} |
||||||
|
|
||||||
|
var error = ( err && err.message ) ? err.message : err; |
||||||
|
res.header('Cache-Control','public'); |
||||||
|
res.json({ error: check.nonEmptyString( error ) ? error : 'internal server error' }); |
||||||
} |
} |
||||||
|
|
||||||
module.exports = middleware; |
module.exports = middleware; |
||||||
|
Loading…
Reference in new issue