feat: update error handler to check for pseudo-standard no-* prefix and route to 404 handler instead

This commit is contained in:
Julian Lam
2023-10-11 13:37:35 -04:00
parent e012edea3b
commit db5b0f47e0

View File

@@ -48,6 +48,12 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
res.status(403).type('text/plain').send(err.message);
},
};
const notFoundHandler = () => {
const controllers = require('.');
controllers['404'].handle404(req, res);
};
const defaultHandler = async function () {
if (res.headersSent) {
return;
@@ -87,6 +93,8 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
try {
if (data.cases.hasOwnProperty(err.code)) {
data.cases[err.code](err, req, res, defaultHandler);
} else if (err.message.startsWith('[[error:no-') && err.message !== '[[error:no-privileges]]') {
notFoundHandler();
} else {
await defaultHandler();
}