ignore props.status in ctx.throw

This commit is contained in:
dead_horse 2014-08-09 13:38:54 +08:00
parent cbe7ad89d7
commit f6626967b2
2 changed files with 23 additions and 3 deletions

View file

@ -75,13 +75,14 @@ var proto = module.exports = {
} }
var err = msg instanceof Error ? msg : new Error(msg); 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) { if (props) {
for (var key in props) err[key] = props[key]; 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; throw err;
}, },

View file

@ -139,4 +139,23 @@ describe('ctx.throw(status, msg, props)', function(){
done(); 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();
}
})
})
}) })