mirror of https://github.com/pelias/api.git
Browse Source
middleware/500.js -Add code to the 500 catchall middleware to report errors to stdout/stderr. -Also, stringify the error via `.toString()` before passing it to `res.json()`, since otherwise an empty object appears to be returned.pull/116/head
Severyn Kozak
10 years ago
1 changed files with 5 additions and 2 deletions
@ -1,9 +1,12 @@ |
|||||||
|
var logger = require( '../src/logger' ); |
||||||
|
|
||||||
// handle application errors
|
// handle application errors
|
||||||
function middleware(err, req, res, next) { |
function middleware(err, req, res, next) { |
||||||
|
logger.error( 'Error:', err ); |
||||||
|
logger.error( 'Stack trace:', err.trace ); |
||||||
res.header('Cache-Control','no-cache'); |
res.header('Cache-Control','no-cache'); |
||||||
if( res.statusCode < 400 ){ res.status(500); } |
if( res.statusCode < 400 ){ res.status(500); } |
||||||
res.json({ error: err }); |
res.json({ error: err.toString() }); |
||||||
} |
} |
||||||
|
|
||||||
module.exports = middleware; |
module.exports = middleware; |
Loading…
Reference in new issue