fix: add named arrow function for request and response handlers (#805)

cherry-pick #804
This commit is contained in:
fengmk2 2017-02-25 14:06:41 +08:00 committed by jongleberry
parent cd02834f75
commit a7c4236728

View file

@ -128,13 +128,16 @@ module.exports = class Application extends Emitter {
if (!this.listeners('error').length) this.on('error', this.onerror); if (!this.listeners('error').length) this.on('error', this.onerror);
return (req, res) => { const handleRequest = (req, res) => {
res.statusCode = 404; res.statusCode = 404;
const ctx = this.createContext(req, res); const ctx = this.createContext(req, res);
const onerror = err => ctx.onerror(err); const onerror = err => ctx.onerror(err);
const handleResponse = () => respond(ctx);
onFinished(res, onerror); onFinished(res, onerror);
fn(ctx).then(() => respond(ctx)).catch(onerror); fn(ctx).then(handleResponse).catch(onerror);
}; };
return handleRequest;
} }
/** /**