Anybody can me explain why this:
.then(content => res.status(200).jsonp(content))
.catch(err => res.status(500).send(err));
In the first example,
.send are invoked as methods on the
res object. This is necessary in order for them to work correctly; they must have access to the response object.
In the second example, you pass a reference to the
.send functions, but when they are invoked they are not invoked as methods on
res. This means that they do not have access to the response object, causing them to fail.
Earlier, I had said you could modify the second example to use
.bind and it should work:
somePromise() .then(res.status(200).jsonp.bind(res)) .catch(res.status(500).send.bind(res));
That is not correct. What happens if you do the above is that the response will always have a 500 status code. That is because the execution goes like this:
.send. Both are bound to
res, which has had its status code set to 500