fix text/plain response for 500 errors

This commit is contained in:
TJ Holowaychuk 2013-09-08 12:07:50 -07:00
parent 28b5b85860
commit 228c38cf3e
2 changed files with 20 additions and 0 deletions

View file

@ -608,6 +608,7 @@ module.exports = {
// respond // respond
this.status = 500; this.status = 500;
this.type = 'text';
this.res.end('Internal Server Error'); this.res.end('Internal Server Error');
}, },

View file

@ -162,6 +162,25 @@ describe('app.respond', function(){
done(); 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(){ describe('when .body is an Object', function(){