add support for .throw(status, msg). Closes #130
This commit is contained in:
parent
5c50b6d0b3
commit
87c03aff61
2 changed files with 18 additions and 4 deletions
|
@ -44,18 +44,18 @@ module.exports = {
|
|||
*
|
||||
* this.throw(403)
|
||||
* this.throw('name required', 400)
|
||||
* this.throw(400, 'name required')
|
||||
* this.throw('something exploded')
|
||||
*
|
||||
* @param {String|Number} msg
|
||||
* @param {Number} status
|
||||
* @param {String|Number} msg or status
|
||||
* @param {String|Number} msg or status
|
||||
* @api public
|
||||
*/
|
||||
|
||||
throw: function(msg, status){
|
||||
// TODO: switch order... feels weird now that im used to express
|
||||
if ('number' == typeof msg) {
|
||||
var tmp = msg;
|
||||
msg = http.STATUS_CODES[tmp];
|
||||
msg = status || http.STATUS_CODES[tmp];
|
||||
status = tmp;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,20 @@ describe('ctx.throw(msg, status)', function(){
|
|||
})
|
||||
})
|
||||
|
||||
describe('ctx.throw(status, msg)', function(){
|
||||
it('should throw an error', function(done){
|
||||
var ctx = context();
|
||||
|
||||
try {
|
||||
ctx.throw(400, 'name required');
|
||||
} catch (err) {
|
||||
assert('name required' == err.message);
|
||||
assert(400 == err.status);
|
||||
done();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('ctx.throw(status)', function(){
|
||||
it('should throw an error', function(done){
|
||||
var ctx = context();
|
||||
|
|
Loading…
Reference in a new issue