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(){