From f6626967b29eb57291d9d5e9bddd0350febc2635 Mon Sep 17 00:00:00 2001 From: dead_horse Date: Sat, 9 Aug 2014 13:38:54 +0800 Subject: [PATCH 1/2] 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(); + } + }) + }) +}) From a85889e6c6508f2bde76d005bd584d19c2a05465 Mon Sep 17 00:00:00 2001 From: dead_horse Date: Sat, 9 Aug 2014 13:39:36 +0800 Subject: [PATCH 2/2] docs: add ctx.headers alias --- docs/api/context.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/context.md b/docs/api/context.md index bece061..708435e 100644 --- a/docs/api/context.md +++ b/docs/api/context.md @@ -119,6 +119,7 @@ this.throw(401, 'access_denied', { user: user }); The following accessors and alias [Request](request.md) equivalents: - `ctx.header` + - `ctx.headers` - `ctx.method` - `ctx.method=` - `ctx.url`