fix edge case where res.respond would not work, misc comments

This commit is contained in:
Matteo Pagliazzi
2016-01-13 18:35:29 +01:00
parent 7a8321ec36
commit 6088b6da42
4 changed files with 6 additions and 4 deletions

View File

@@ -74,5 +74,7 @@ export default function errorHandler (err, req, res, next) { // eslint-disable-l
if (responseErr.errors) jsonRes.errors = responseErr.errors;
return res.respond(responseErr.httpCode, jsonRes);
// In some occasions like when invalid JSON is supplied `res.respond` might be not yet avalaible,
// in this case we use the standard res.status(...).json(...)
return res.respond ? res.respond(responseErr.httpCode, jsonRes) : res.status(responseErr.httpCode).json(jsonRes);
}