Skip to content

Commit

Permalink
[breaking change] don't bind onerror to context (koajs#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored Aug 29, 2016
1 parent 614b4e1 commit 4338cb6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 4338cb6

Please sign in to comment.