better 404 handling; /address: fix catch issue

This commit is contained in:
Dan Janosik 2021-07-25 12:09:54 -04:00
parent 54eae151dc
commit ee77a79736
No known key found for this signature in database
GPG key ID: 846311D3D259BFF1
2 changed files with 14 additions and 3 deletions

15
app.js
View file

@ -846,12 +846,23 @@ expressApp.use(function(req, res, next) {
/// error handlers
const sharedErrorHandler = (err) => {
if (err && err.message && err.message.includes("Not Found")) {
const path = err.toString().substring(err.toString().lastIndexOf(" ") + 1);
utils.logError(`NotFound-${path}`, err);
} else {
utils.logError("ExpressUncaughtError", err);
}
};
// development error handler
// will print stacktrace
if (expressApp.get("env") === "development" || expressApp.get("env") === "local") {
expressApp.use(function(err, req, res, next) {
if (err) {
utils.logError("3289023yege", err);
sharedErrorHandler(err);
}
res.status(err.status || 500);
@ -866,7 +877,7 @@ if (expressApp.get("env") === "development" || expressApp.get("env") === "local"
// no stacktraces leaked to user
expressApp.use(function(err, req, res, next) {
if (err) {
utils.logError("2309832hcxwgeeew", err);
sharedErrorHandler(err);
}
res.status(err.status || 500);

View file

@ -1644,7 +1644,7 @@ router.get("/address/:address", asyncHandler(async (req, res, next) => {
next();
} catch (e) {
res.locals.pageErrors.push(utils.logError("2108hs0gsdfe", err, {address:address}));
res.locals.pageErrors.push(utils.logError("2108hs0gsdfe", e, {address:address}));
res.locals.userMessageMarkdown = `Failed to load address: **${address}**`;