From 7d9c6ba66c38c580b3d7a628a364661a5afcd2d5 Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Mon, 18 Nov 2013 17:38:12 -0800 Subject: [PATCH] context: .error() -> .throw() .error() still works for compatibility, but it will be removed in the future. closes #94 --- lib/context.js | 21 +++++++++++++++++---- test/context/error.js | 12 ++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/context.js b/lib/context.js index 654915d..dcf2857 100644 --- a/lib/context.js +++ b/lib/context.js @@ -45,16 +45,16 @@ module.exports = { * defaulting to 500. Note that these are user-level * errors, and the message may be exposed to the client. * - * this.error(403) - * this.error('name required', 400) - * this.error('something exploded') + * this.throw(403) + * this.throw('name required', 400) + * this.throw('something exploded') * * @param {String|Number} msg * @param {Number} status * @api public */ - error: function(msg, status){ + throw: function(msg, status){ // TODO: switch order... feels weird now that im used to express if ('number' == typeof msg) { var tmp = msg; @@ -68,6 +68,19 @@ module.exports = { throw err; }, + /** + * Alias for .throw() for backwards compatibility. + * Do not use - will be removed in the future. + * + * @param {String|Number} msg + * @param {Number} status + * @api private + */ + + error: function(msg, status){ + this.throw(msg, status); + }, + /** * Default error handling. * diff --git a/test/context/error.js b/test/context/error.js index 8409b46..c044565 100644 --- a/test/context/error.js +++ b/test/context/error.js @@ -2,12 +2,12 @@ var context = require('../context'); var assert = require('assert'); -describe('ctx.error(msg)', function(){ +describe('ctx.throw(msg)', function(){ it('should set .status to 500', function(done){ var ctx = context(); try { - ctx.error('boom'); + ctx.throw('boom'); } catch (err) { assert(500 == err.status); done(); @@ -15,12 +15,12 @@ describe('ctx.error(msg)', function(){ }) }) -describe('ctx.error(msg, status)', function(){ +describe('ctx.throw(msg, status)', function(){ it('should throw an error', function(done){ var ctx = context(); try { - ctx.error('name required', 400); + ctx.throw('name required', 400); } catch (err) { assert('name required' == err.message); assert(400 == err.status); @@ -29,12 +29,12 @@ describe('ctx.error(msg, status)', function(){ }) }) -describe('ctx.error(status)', function(){ +describe('ctx.throw(status)', function(){ it('should throw an error', function(done){ var ctx = context(); try { - ctx.error(400); + ctx.throw(400); } catch (err) { assert('Bad Request' == err.message); assert(400 == err.status);