Skip to content

Commit

Permalink
doc: updated docs for throw() to pass status as first param. (#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaleedAshraf authored and dead-horse committed Nov 1, 2018
1 parent 6c0e0d6 commit 88b92b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/api/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ throw err;
ctx.throw(401, 'access_denied', { user: user });
```

Koa uses [http-errors](https://github.com/jshttp/http-errors) to create errors.
Koa uses [http-errors](https://github.com/jshttp/http-errors) to create errors. `status` should only be passed as the first parameter.

### ctx.assert(value, [status], [msg], [properties])

Expand Down
11 changes: 6 additions & 5 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ const proto = module.exports = {
assert: httpAssert,

/**
* Throw an error with `msg` and optional `status`
* defaulting to 500. Note that these are user-level
* Throw an error with `status` (default 500) and
* `msg`. Note that these are user-level
* errors, and the message may be exposed to the client.
*
* this.throw(403)
* this.throw('name required', 400)
* this.throw(400, 'name required')
* this.throw('something exploded')
* this.throw(new Error('invalid'), 400);
* this.throw(400, new Error('invalid'));
* this.throw(new Error('invalid'))
* this.throw(400, new Error('invalid'))
*
* See: https://github.com/jshttp/http-errors
*
* Note: `stats` should only be passed as the first parameter.
*
* @param {String|Number|Error} err, msg or status
* @param {String|Number|Error} [err, msg or status]
* @param {Object} [props]
Expand Down

0 comments on commit 88b92b4

Please sign in to comment.