fix: add named arrow function for request and response handlers (#805)
cherry-pick #804
This commit is contained in:
parent
cd02834f75
commit
a7c4236728
1 changed files with 5 additions and 2 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue