fixing enableExpressErrorHandler logic (#6423)

* fixing enableExpressErrorHandler logic

* Fix tests

Co-authored-by: n.andryukhin <n.andryukhin@mediasoft.team>
Co-authored-by: Diamond Lewis <findlewis@gmail.com>
This commit is contained in:
Nikolay Andryukhin
2020-03-23 09:49:12 +04:00
committed by GitHub
parent 927676b34e
commit c178acd347
2 changed files with 7 additions and 17 deletions

View File

@@ -325,6 +325,9 @@ export function allowMethodOverride(req, res, next) {
export function handleParseErrors(err, req, res, next) {
const log = (req.config && req.config.loggerController) || defaultLogger;
if (err instanceof Parse.Error) {
if (req.config && req.config.enableExpressErrorHandler) {
return next(err);
}
let httpStatus;
// TODO: fill out this mapping
switch (err.code) {
@@ -337,13 +340,9 @@ export function handleParseErrors(err, req, res, next) {
default:
httpStatus = 400;
}
res.status(httpStatus);
res.json({ code: err.code, error: err.message });
log.error('Parse error: ', err);
if (req.config && req.config.enableExpressErrorHandler) {
next(err);
}
} else if (err.status && err.message) {
res.status(err.status);
res.json({ error: err.message });