add err.expose check for response handler to expose the err.message
This commit is contained in:
parent
6db24f9fac
commit
fc25b79b99
2 changed files with 23 additions and 1 deletions
|
@ -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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue