add .assert() docs
This commit is contained in:
parent
2f0fe55ae3
commit
85da935759
1 changed files with 17 additions and 3 deletions
|
@ -60,7 +60,7 @@ app.use(function *(){
|
|||
|
||||
- `signed` the cookie requested should be signed
|
||||
|
||||
Note: 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.cookies.set(name, value, [options])
|
||||
|
||||
|
@ -73,9 +73,9 @@ Note: koa uses the [cookies](https://github.com/jed/cookies) module where option
|
|||
- `secure` secure cookie
|
||||
- `httpOnly` server-accessible cookie, __true__ by default
|
||||
|
||||
Note: 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([msg], [status], [properties])
|
||||
|
||||
Helper method to throw an error with a `.status` property
|
||||
defaulting to `500` that will allow Koa to respond appropriately.
|
||||
|
@ -109,6 +109,20 @@ this.throw(401, 'access_denied', { user: user });
|
|||
this.throw('access_denied', { user: user });
|
||||
```
|
||||
|
||||
koa uses [http-errors](https://github.com/jshttp/http-errors) to create errors.
|
||||
|
||||
### ctx.assert(value, [msg], [status], [properties])
|
||||
|
||||
Helper method to throw an error similar to `.throw()`
|
||||
when `!value`. Similar to node's [assert()](http://nodejs.org/api/assert.html)
|
||||
method.
|
||||
|
||||
```js
|
||||
this.assert(this.user, 401, 'User not found. Please login!');
|
||||
```
|
||||
|
||||
koa uses [http-assert](https://github.com/jshttp/http-assert) for assertions.
|
||||
|
||||
### ctx.respond
|
||||
|
||||
To bypass Koa's built-in response handling, you may explicitly set `this.respond = false;`. Use this if you want to write to the raw `res` object instead of letting Koa handle the response for you.
|
||||
|
|
Loading…
Reference in a new issue