mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: update error handler to check for pseudo-standard no-* prefix and route to 404 handler instead
This commit is contained in:
@@ -48,6 +48,12 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
|
|||||||
res.status(403).type('text/plain').send(err.message);
|
res.status(403).type('text/plain').send(err.message);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const notFoundHandler = () => {
|
||||||
|
const controllers = require('.');
|
||||||
|
controllers['404'].handle404(req, res);
|
||||||
|
};
|
||||||
|
|
||||||
const defaultHandler = async function () {
|
const defaultHandler = async function () {
|
||||||
if (res.headersSent) {
|
if (res.headersSent) {
|
||||||
return;
|
return;
|
||||||
@@ -87,6 +93,8 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
|
|||||||
try {
|
try {
|
||||||
if (data.cases.hasOwnProperty(err.code)) {
|
if (data.cases.hasOwnProperty(err.code)) {
|
||||||
data.cases[err.code](err, req, res, defaultHandler);
|
data.cases[err.code](err, req, res, defaultHandler);
|
||||||
|
} else if (err.message.startsWith('[[error:no-') && err.message !== '[[error:no-privileges]]') {
|
||||||
|
notFoundHandler();
|
||||||
} else {
|
} else {
|
||||||
await defaultHandler();
|
await defaultHandler();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user