|
|
@ -381,6 +381,35 @@ Controllers.handle404 = function(req, res) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Controllers.handleURIErrors = function(err, req, res, next) {
|
|
|
|
|
|
|
|
// Handle cases where malformed URIs are passed in
|
|
|
|
|
|
|
|
if (err instanceof URIError) {
|
|
|
|
|
|
|
|
var tidMatch = req.path.match(/^\/topic\/(\d+)\//);
|
|
|
|
|
|
|
|
var cidMatch = req.path.match(/^\/category\/(\d+)\//);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tidMatch) {
|
|
|
|
|
|
|
|
res.redirect(nconf.get('relative_path') + tidMatch[0]);
|
|
|
|
|
|
|
|
} else if (cidMatch) {
|
|
|
|
|
|
|
|
res.redirect(nconf.get('relative_path') + cidMatch[0]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
winston.warn('[controller] Bad request: ' + req.path);
|
|
|
|
|
|
|
|
if (res.locals.isAPI) {
|
|
|
|
|
|
|
|
res.status(400).json({
|
|
|
|
|
|
|
|
error: '[[global:400.title]]'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
req.app.locals.middleware.buildHeader(req, res, function() {
|
|
|
|
|
|
|
|
res.render('400', { error: validator.escape(String(err.message)) });
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Controllers.handleErrors = function(err, req, res, next) {
|
|
|
|
Controllers.handleErrors = function(err, req, res, next) {
|
|
|
|
switch (err.code) {
|
|
|
|
switch (err.code) {
|
|
|
|
case 'EBADCSRFTOKEN':
|
|
|
|
case 'EBADCSRFTOKEN':
|
|
|
@ -403,7 +432,7 @@ Controllers.handleErrors = function(err, req, res, next) {
|
|
|
|
res.json({path: validator.escape(path), error: err.message});
|
|
|
|
res.json({path: validator.escape(path), error: err.message});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
req.app.locals.middleware.buildHeader(req, res, function() {
|
|
|
|
req.app.locals.middleware.buildHeader(req, res, function() {
|
|
|
|
res.render('500', {path: validator.escape(path), error: validator.escape(String(err.message))});
|
|
|
|
res.render('500', { path: validator.escape(path), error: validator.escape(String(err.message)) });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|