How to use Youch with express?
brunoti opened this issue · comments
Don't know. I don't use express.
Thanks man!
const Youch = require('youch');
// after routes
app.use((error, req, res, next) => {
if (error && process.env.NODE_ENV !== 'production' && !res.headersSent) {
const youch = new Youch(error, req);
return youch
.toHTML()
.then(html => (
res
.status(500)
.set('Content-Type', 'text/html')
.send(html)
))
}
next(error);
});
@ajitid You probably want to set the status code to 500 or something as well.