support errors and update docs
This commit is contained in:
parent
5931714bd8
commit
dc0c35471c
2 changed files with 18 additions and 1 deletions
|
@ -102,10 +102,11 @@ throw err;
|
|||
error messages since you do not want to leak failure
|
||||
details.
|
||||
|
||||
You may optionall pass a `properties` object which is merged into the error as-is, useful for decorating machine-friendly errors which are reported to the requester upstream.
|
||||
You may optionally pass a `properties` object which is merged into the error as-is, useful for decorating machine-friendly errors which are reported to the requester upstream.
|
||||
|
||||
```js
|
||||
this.throw(401, 'access_denied', { user: user });
|
||||
this.throw('access_denied', { user: user });
|
||||
```
|
||||
|
||||
### ctx.respond
|
||||
|
|
|
@ -191,3 +191,19 @@ describe('ctx.throw(status, props)', function(){
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('ctx.throw(err, props)', function(){
|
||||
it('should mixin props', function(done){
|
||||
var ctx = context();
|
||||
|
||||
try {
|
||||
ctx.throw(new Error('test'), { prop: true });
|
||||
} catch (err) {
|
||||
assert('test' == err.message);
|
||||
assert(500 == err.status);
|
||||
assert(false === err.expose);
|
||||
assert(true === err.prop);
|
||||
done();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue