[breaking change] don't bind onerror to context (#800)

This commit is contained in:
Yiyu He 2016-08-29 11:18:30 +08:00 committed by GitHub
parent 614b4e1ad7
commit 4338cb6c14
2 changed files with 4 additions and 4 deletions

View file

@ -131,8 +131,9 @@ module.exports = class Application extends Emitter {
return (req, res) => {
res.statusCode = 404;
const ctx = this.createContext(req, res);
onFinished(res, ctx.onerror);
fn(ctx).then(() => respond(ctx)).catch(ctx.onerror);
const onerror = err => ctx.onerror(err);
onFinished(res, onerror);
fn(ctx).then(() => respond(ctx)).catch(onerror);
};
}
@ -152,7 +153,6 @@ module.exports = class Application extends Emitter {
request.ctx = response.ctx = context;
request.response = response;
response.request = request;
context.onerror = context.onerror.bind(context);
context.originalUrl = request.originalUrl = req.url;
context.cookies = new Cookies(req, res, {
keys: this.keys,

View file

@ -164,7 +164,7 @@ module.exports = {
// stream
if ('function' == typeof val.pipe) {
onFinish(this.res, destroy.bind(null, val));
ensureErrorHandler(val, this.ctx.onerror);
ensureErrorHandler(val, err => this.ctx.onerror(err));
// overwriting
if (null != original && original != val) this.remove('Content-Length');