Merge pull request #288 from dead-horse/issue287

asset non-error obj in app.onerror, fixed #287
master
TJ Holowaychuk 2014-06-05 16:35:17 -07:00
commit f68716d8b4
2 changed files with 9 additions and 5 deletions

View File

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

View File

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