From 4338cb6c140b88281cc22c195cd0b440ea4645b1 Mon Sep 17 00:00:00 2001 From: Yiyu He Date: Mon, 29 Aug 2016 11:18:30 +0800 Subject: [PATCH] [breaking change] don't bind onerror to context (#800) --- lib/application.js | 6 +++--- lib/response.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/application.js b/lib/application.js index 741fff9..d0ceba0 100644 --- a/lib/application.js +++ b/lib/application.js @@ -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, diff --git a/lib/response.js b/lib/response.js index 01c5c1d..87ece39 100644 --- a/lib/response.js +++ b/lib/response.js @@ -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');