assert non-error obj pass to app.onerror, fixed #287

This commit is contained in:
dead_horse 2014-05-23 21:15:03 +08:00
parent 851160e0ae
commit 4979077562
2 changed files with 9 additions and 5 deletions

View file

@ -155,10 +155,15 @@ app.createContext = function(req, res){
*/ */
app.onerror = function(err){ app.onerror = function(err){
if (!err) return;
assert(err instanceof Error, 'non-error thrown: ' + err);
if (404 == err.status) return; if (404 == err.status) return;
if ('test' == this.env) return; if ('test' == this.env) return;
var msg = err.stack || err.toString();
console.error(); console.error();
console.error(err.stack.replace(/^/gm, ' ')); console.error(msg.replace(/^/gm, ' '));
console.error(); console.error();
}; };

View file

@ -91,18 +91,17 @@ var proto = module.exports = {
assert(err instanceof Error, 'non-error thrown: ' + err); assert(err instanceof Error, 'non-error thrown: ' + err);
// delegate
this.app.emit('error', err, this);
// nothing we can do here other // nothing we can do here other
// than delegate to the app-level // than delegate to the app-level
// handler and log. // handler and log.
if (this.headerSent || !this.writable) { if (this.headerSent || !this.writable) {
err.headerSent = true; err.headerSent = true;
this.app.emit('error', err, this);
return; return;
} }
// delegate
this.app.emit('error', err, this);
// unset all headers // unset all headers
this.res._headers = {}; this.res._headers = {};