From 17bb6db6e56e5c6b96ab1d9b06d57889d1b651c9 Mon Sep 17 00:00:00 2001 From: Severyn Kozak Date: Mon, 27 Apr 2015 11:53:29 -0400 Subject: [PATCH] Resolve #114: report runtime errors. 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. --- middleware/500.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/middleware/500.js b/middleware/500.js index d73c5684..15846ce0 100644 --- a/middleware/500.js +++ b/middleware/500.js @@ -1,9 +1,12 @@ +var logger = require( '../src/logger' ); // handle application errors function middleware(err, req, res, next) { + logger.error( 'Error:', err ); + logger.error( 'Stack trace:', err.trace ); res.header('Cache-Control','no-cache'); if( res.statusCode < 400 ){ res.status(500); } - res.json({ error: err }); + res.json({ error: err.toString() }); } -module.exports = middleware; \ No newline at end of file +module.exports = middleware;