In express, how do I route to a custom error template when a condition is met? In express, how do I route to a custom error template when a condition is met? express express

In express, how do I route to a custom error template when a condition is met?


Looking at the docs, you should either send your response object as:

res.render('error', { "error": {status: 500, stack: 'error' } });

Or in your pug template, access it as first level member like:

#error.pugextends layoutblock content  h1= message  h2= status  pre #{stack}


This is how it works for me

res.status(404).render('errorPage', {  title: '404 - page nt found!'});

for your needs it could be

res.status(500).render('error', {  status: 500,   stack: 'error'});