diff --git a/lib/context.js b/lib/context.js index 050ea1a..4477c69 100644 --- a/lib/context.js +++ b/lib/context.js @@ -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; } diff --git a/test/context/throw.js b/test/context/throw.js index c044565..d3b25a2 100644 --- a/test/context/throw.js +++ b/test/context/throw.js @@ -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();