catch error in express code example
Example 1: how to handle all error of all router in express
const handleErrorAsync = func => (req, res, next) => {
func(req, res, next).catch((error) => next(error));
};
Example 2: error handler
function handlerError(request, response){
response.status(500).send('opps');
}
.catch(handlerError);
Example 3: express generator error handling
app.get('/', function (req, res) {
throw new Error('BROKEN') // Express will catch this on its own.
})