Browse Source

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.
pull/116/head
Severyn Kozak 10 years ago
parent
commit
17bb6db6e5
  1. 5
      middleware/500.js

5
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;
Loading…
Cancel
Save