Moved JSON error handlers next to each other

- helps for comparing and contrasting
- context is largely lost on why we have these two, need to figure it out and if possible, simplify
This commit is contained in:
Hannah Wolfe 2021-11-24 11:42:53 +00:00
parent f417c4c732
commit 0c4c9ce553
No known key found for this signature in database
GPG Key ID: AB586C3B5AE5C037

View File

@ -123,6 +123,23 @@ _private.JSONErrorRenderer = (err, req, res, next) => { // eslint-disable-line n
});
};
_private.JSONErrorRendererV2 = (err, req, res, next) => { // eslint-disable-line no-unused-vars
const userError = _private.prepareUserMessage(err, req);
res.json({
errors: [{
message: userError.message || null,
context: userError.context || null,
type: err.errorType || null,
details: err.errorDetails || null,
property: err.property || null,
help: err.help || null,
code: err.code || null,
id: err.id || null
}]
});
};
_private.prepareUserMessage = (err, res) => {
const userError = {
message: err.message,
@ -169,23 +186,6 @@ _private.prepareUserMessage = (err, res) => {
return userError;
};
_private.JSONErrorRendererV2 = (err, req, res, next) => { // eslint-disable-line no-unused-vars
const userError = _private.prepareUserMessage(err, req);
res.json({
errors: [{
message: userError.message || null,
context: userError.context || null,
type: err.errorType || null,
details: err.errorDetails || null,
property: err.property || null,
help: err.help || null,
code: err.code || null,
id: err.id || null
}]
});
};
_private.ErrorFallbackMessage = err => `<h1>${tpl(messages.oopsErrorTemplateHasError)}</h1>
<p>${tpl(messages.encounteredError)}</p>
<pre>${escapeExpression(err.message || err)}</pre>