Answer the question
In order to leave comments, you need to log in
How to catch a URL with an error in a template engine?
I ran into a problem, a big project, decent traffic, and from time to time errors fly out in the pm2 logs
TypeError: Cannot read property 'href' of undefined
at eval (eval at wrap (/var/www/site.ru/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:19:718)
at template (eval at wrap (/var/www/site.ru/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:41:78)
at Object.exports.renderFile (/var/www/site.ru/node_modules/pug/lib/index.js:427:38)
at Object.exports.renderFile (/var/www/site.ru/node_modules/pug/lib/index.js:417:21)
at View.exports.__express [as engine] (/var/www/site.ru/node_modules/pug/lib/index.js:464:11)
at View.render (/var/www/site.ru/node_modules/express/lib/view.js:135:8)
at tryRender (/var/www/site.ru/node_modules/express/lib/application.js:640:10)
at Function.render (/var/www/site.ru/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/var/www/site.ru/node_modules/express/lib/response.js:1008:7)
at /var/www/site.ru/index.js:109:14
at Layer.handle_error (/var/www/site.ru/node_modules/express/lib/router/layer.js:71:5)
at trim_prefix (/var/www/site.ru/node_modules/express/lib/router/index.js:315:13)
at /var/www/site.ru/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/var/www/site.ru/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/site.ru/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/var/www/site.ru/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/var/www/site.ru/node_modules/express/lib/router/index.js:315:13)
at /var/www/site.ru/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/var/www/site.ru/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/site.ru/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/var/www/site.ru/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/var/www/site.ru/node_modules/express/lib/router/index.js:315:13)
// error handler
app.use(function(e, request, response, next) {
if (request.headers['x-requested-with'] == 'XMLHttpRequest') return response.status(e.status || 403), response.send(e.message)
if(e.code == 'EBADCSRFTOKEN') e.message = 'Переданный вами токен недействителен ;('
response.locals.message = e.message
response.locals.error = request.app.get('env') === 'development' ? e : {}
response.status(e.status || 500)
if(e.status > 404) console.log(e)
response.render('error', { page: {
name: `${e.status} ${e.message}`
} })
})
response.render('error', { page: {
app.use(require('./libs/language'))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question