Error handling middleware for Express applications. Catches 404 errors and provides customizable error handling through hooks.
// Custom error handling in config/config.jsexport default { hook_handle_error: (error, req, res, next) => { if (error.status === 404) res.render('error/404'); else res.render('error/500'); }}; Copy
// Custom error handling in config/config.jsexport default { hook_handle_error: (error, req, res, next) => { if (error.status === 404) res.render('error/404'); else res.render('error/500'); }};
Static
Mount error handling middleware on Express application. Sets up 404 error catching and custom error handling hooks.
Express application instance
// This method is called automatically by express-sweet.mount()import ErrorHandler from './middlewares/ErrorHandler';await ErrorHandler.mount(app); Copy
// This method is called automatically by express-sweet.mount()import ErrorHandler from './middlewares/ErrorHandler';await ErrorHandler.mount(app);
Error handling middleware for Express applications. Catches 404 errors and provides customizable error handling through hooks.
Example