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

cherry-pick #804
master
fengmk2 2017-02-25 14:06:41 +08:00 committed by jongleberry
parent cd02834f75
commit a7c4236728
1 changed files with 5 additions and 2 deletions

View File

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