1function errorHandler (err, req, res, next) {
2 if (res.headersSent) {
3 return next(err)
4 }
5 res.status(500)
6 res.render('error', { error: err })
7}
8
1app.get('/', function (req, res) {
2 throw new Error('BROKEN') // Express will catch this on its own.
3})
4