Merge pull request #333 from dead-horse/throw
ignore props.status in ctx.throw
This commit is contained in:
commit
70c72df110
3 changed files with 24 additions and 3 deletions
|
@ -119,6 +119,7 @@ this.throw(401, 'access_denied', { user: user });
|
|||
The following accessors and alias [Request](request.md) equivalents:
|
||||
|
||||
- `ctx.header`
|
||||
- `ctx.headers`
|
||||
- `ctx.method`
|
||||
- `ctx.method=`
|
||||
- `ctx.url`
|
||||
|
|
|
@ -75,13 +75,14 @@ var proto = module.exports = {
|
|||
}
|
||||
|
||||
var err = msg instanceof Error ? msg : new Error(msg);
|
||||
err.status = status || err.status || 500;
|
||||
err.expose = 'number' == typeof err.status && http.STATUS_CODES[err.status] && err.status < 500;
|
||||
|
||||
if (props) {
|
||||
for (var key in props) err[key] = props[key];
|
||||
}
|
||||
|
||||
err.status = status || err.status || 500;
|
||||
err.expose = 'number' == typeof err.status && http.STATUS_CODES[err.status] && err.status < 500;
|
||||
|
||||
throw err;
|
||||
},
|
||||
|
||||
|
|
|
@ -139,4 +139,23 @@ describe('ctx.throw(status, msg, props)', function(){
|
|||
done();
|
||||
}
|
||||
})
|
||||
|
||||
describe('when props include status', function(){
|
||||
it('should be ignored', function(done){
|
||||
var ctx = context();
|
||||
|
||||
try {
|
||||
ctx.throw(400, 'msg', {
|
||||
prop: true,
|
||||
status: -1
|
||||
});
|
||||
} catch (err) {
|
||||
assert('msg' == err.message);
|
||||
assert(400 == err.status);
|
||||
assert(true === err.expose);
|
||||
assert(true === err.prop);
|
||||
done();
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue