add ENOENT err.code support for 404

This commit is contained in:
TJ Holowaychuk 2013-09-08 12:11:02 -07:00
parent 228c38cf3e
commit 091d5010cd
2 changed files with 11 additions and 10 deletions

View File

@ -599,17 +599,18 @@ module.exports = {
// delegate
this.app.emit('error', err, this);
// err.status support
if (err.status) {
this.status = err.status;
this.res.end(http.STATUS_CODES[err.status]);
return;
}
// force text/plain
this.type = 'text';
// ENOENT support
if ('ENOENT' == err.code) err.status = 404;
// default to 500
err.status = err.status || 500;
// respond
this.status = 500;
this.type = 'text';
this.res.end('Internal Server Error');
this.status = err.status;
this.res.end(http.STATUS_CODES[err.status]);
},
/**

View File

@ -178,7 +178,7 @@ describe('app.respond', function(){
request(server)
.get('/')
.expect('Content-Type', 'text/plain')
.expect(500)
.expect(404)
.end(done);
})
})