Skip to content

Commit

Permalink
fix: add named arrow function for request and response handlers (#805)
Browse files Browse the repository at this point in the history
cherry-pick #804
  • Loading branch information
fengmk2 authored and jonathanong committed Feb 25, 2017
1 parent cd02834 commit a7c4236
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit a7c4236

Please sign in to comment.