From f6626967b29eb57291d9d5e9bddd0350febc2635 Mon Sep 17 00:00:00 2001 From: dead_horse Date: Sat, 9 Aug 2014 13:38:54 +0800 Subject: [PATCH] ignore props.status in ctx.throw --- lib/context.js | 5 +++-- test/context/throw.js | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/context.js b/lib/context.js index 0c3ea57..2daa816 100644 --- a/lib/context.js +++ b/lib/context.js @@ -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; }, diff --git a/test/context/throw.js b/test/context/throw.js index 7c49259..158c9ae 100644 --- a/test/context/throw.js +++ b/test/context/throw.js @@ -139,4 +139,23 @@ describe('ctx.throw(status, msg, props)', function(){ done(); } }) -}) \ No newline at end of file + + 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(); + } + }) + }) +})