Skip to content

Commit 88b92b4

Browse files
WaleedAshrafdead-horse
authored andcommitted
doc: updated docs for throw() to pass status as first param. (#1268)
1 parent 6c0e0d6 commit 88b92b4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

docs/api/context.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ throw err;
118118
ctx.throw(401, 'access_denied', { user: user });
119119
```
120120

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

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

lib/context.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,20 @@ const proto = module.exports = {
7373
assert: httpAssert,
7474

7575
/**
76-
* Throw an error with `msg` and optional `status`
77-
* defaulting to 500. Note that these are user-level
76+
* Throw an error with `status` (default 500) and
77+
* `msg`. Note that these are user-level
7878
* errors, and the message may be exposed to the client.
7979
*
8080
* this.throw(403)
81-
* this.throw('name required', 400)
8281
* this.throw(400, 'name required')
8382
* this.throw('something exploded')
84-
* this.throw(new Error('invalid'), 400);
85-
* this.throw(400, new Error('invalid'));
83+
* this.throw(new Error('invalid'))
84+
* this.throw(400, new Error('invalid'))
8685
*
8786
* See: https://github.com/jshttp/http-errors
8887
*
88+
* Note: `stats` should only be passed as the first parameter.
89+
*
8990
* @param {String|Number|Error} err, msg or status
9091
* @param {String|Number|Error} [err, msg or status]
9192
* @param {Object} [props]

0 commit comments

Comments
 (0)