diff --git a/lib/application.js b/lib/application.js index cd8a85e..2d9b561 100644 --- a/lib/application.js +++ b/lib/application.js @@ -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; } /**