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` 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(); + } + }) + }) +})