add err.expose check for response handler to expose the err.message

This commit is contained in:
TJ Holowaychuk 2013-09-12 08:05:50 -07:00
parent 6db24f9fac
commit fc25b79b99
2 changed files with 23 additions and 1 deletions

View file

@ -611,8 +611,10 @@ module.exports = {
err.status = err.status || 500; err.status = err.status || 500;
// respond // respond
var code = http.STATUS_CODES[err.status];
var msg = err.expose ? err.message : code;
this.status = err.status; this.status = err.status;
this.res.end(http.STATUS_CODES[err.status]); this.res.end(msg);
}, },
/** /**

View file

@ -243,6 +243,26 @@ describe('app.respond', function(){
.end(function(){}); .end(function(){});
}) })
describe('with an .expose property', function(){
it('should expose the message', function(done){
var app = koa();
app.use(function(next){
return function *(){
var err = new Error('sorry!');
err.status = 403;
err.expose = true;
throw err;
}
});
request(app.listen())
.get('/')
.expect(403, 'sorry!')
.end(done);
})
})
describe('with a .status property', function(){ describe('with a .status property', function(){
it('should respond with .status', function(done){ it('should respond with .status', function(done){
var app = koa(); var app = koa();