Mount error handling middleware on Express application.
Catches 404 errors and provides customizable error handling through hooks. 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.js';
await errorHandler(app);
// Custom error handling in config/config.js
export default {
/**
* Custom error handler hook, defaults to undefined.
* @type {((error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void)|undefined}
*/
hook_handle_error: (error, req, res, next) => {
if (error.status === 404)
res.render('error/404');
else
res.render('error/500');
}
};
Error handling middleware