From 091d5010cd4762eccd246141aa932cb88031c30b Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Sun, 8 Sep 2013 12:11:02 -0700 Subject: [PATCH] add ENOENT err.code support for 404 --- lib/context.js | 19 ++++++++++--------- test/application.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/context.js b/lib/context.js index b61d443..be4848c 100644 --- a/lib/context.js +++ b/lib/context.js @@ -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]); }, /** diff --git a/test/application.js b/test/application.js index 1ae2138..444c27d 100644 --- a/test/application.js +++ b/test/application.js @@ -178,7 +178,7 @@ describe('app.respond', function(){ request(server) .get('/') .expect('Content-Type', 'text/plain') - .expect(500) + .expect(404) .end(done); }) })