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 // delegate
this.app.emit('error', err, this); this.app.emit('error', err, this);
// err.status support // force text/plain
if (err.status) { this.type = 'text';
this.status = err.status;
this.res.end(http.STATUS_CODES[err.status]); // ENOENT support
return; if ('ENOENT' == err.code) err.status = 404;
}
// default to 500
err.status = err.status || 500;
// respond // respond
this.status = 500; this.status = err.status;
this.type = 'text'; this.res.end(http.STATUS_CODES[err.status]);
this.res.end('Internal Server Error');
}, },
/** /**

View File

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