docs: fix documentation to match new http-errors API (#957) (#967)

This commit is contained in:
Remek Ambroziak 2017-04-21 15:49:06 +02:00 committed by Yiyu He
parent cd5d6a1c37
commit 7f3d0765d7

View file

@ -85,20 +85,19 @@ koa uses the [cookies](https://github.com/jed/cookies) module where options are
koa uses the [cookies](https://github.com/jed/cookies) module where options are simply passed. koa uses the [cookies](https://github.com/jed/cookies) module where options are simply passed.
### ctx.throw([msg], [status], [properties]) ### ctx.throw([status], [msg], [properties])
Helper method to throw an error with a `.status` property Helper method to throw an error with a `.status` property
defaulting to `500` that will allow Koa to respond appropriately. defaulting to `500` that will allow Koa to respond appropriately.
The following combinations are allowed: The following combinations are allowed:
```js ```js
ctx.throw(403); ctx.throw(400);
ctx.throw('name required', 400);
ctx.throw(400, 'name required'); ctx.throw(400, 'name required');
ctx.throw('something exploded'); ctx.throw(400, 'name required', { user: user });
``` ```
For example `ctx.throw('name required', 400)` is equivalent to: For example `ctx.throw(400, 'name required')` is equivalent to:
```js ```js
const err = new Error('name required'); const err = new Error('name required');
@ -117,7 +116,6 @@ throw err;
```js ```js
ctx.throw(401, 'access_denied', { user: user }); ctx.throw(401, 'access_denied', { user: user });
ctx.throw('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.