From 228c38cf3ea4fe5db7b98ebb902611a507aa9b84 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Sun, 8 Sep 2013 12:07:50 -0700 Subject: [PATCH] fix text/plain response for 500 errors --- lib/context.js | 1 + test/application.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/context.js b/lib/context.js index 2f367af..b61d443 100644 --- a/lib/context.js +++ b/lib/context.js @@ -608,6 +608,7 @@ module.exports = { // respond this.status = 500; + this.type = 'text'; this.res.end('Internal Server Error'); }, diff --git a/test/application.js b/test/application.js index be5ebba..1ae2138 100644 --- a/test/application.js +++ b/test/application.js @@ -162,6 +162,25 @@ describe('app.respond', function(){ done(); }); }) + + it('should handle errors', function(done){ + var app = koa(); + + app.use(function(next){ + return function *(){ + this.set('Content-Type', 'application/json'); + this.body = fs.createReadStream('does not exist'); + } + }); + + var server = app.listen(); + + request(server) + .get('/') + .expect('Content-Type', 'text/plain') + .expect(500) + .end(done); + }) }) describe('when .body is an Object', function(){