Ajout de la base de données MySQL

This commit is contained in:
Rampeur
2025-08-13 21:51:07 +02:00
parent be44e4fdf0
commit 49b1a3f6b3
35 changed files with 1579 additions and 37 deletions
+49
View File
@@ -0,0 +1,49 @@
var appEnv = process.env.APP_ENV;
if (appEnv == undefined) {
appEnv = 'development';
}
const isProduction = appEnv === 'production',
chalk = require('chalk'),
utils = require('../routes/utils');
const exceptionHandler = {
notFoundErrorHandler: (req, res, next) => {
let err = new Error('Not Found');
err.status = 404;
console.log(`${utils.getDateTimeISOString()}`, chalk.yellow(`${err.status} ${err.message}`));
next(err);
},
logErrorHandler: (err, req, res, next) => {
console.log(`${utils.getDateTimeISOString()}`, chalk.red(`error handler : ${err.message} ${err.err}`));
console.error(err.stack);
next(err);
},
clientErrorHandler: (err, req, res, next) => {
if (req.xhr) {
res.status(err.status || 500);
} else {
next(err);
}
},
// eslint-disable-next-line no-unused-vars
fianlErrorHandler: (err, req, res, next) => {
res.status(err.status || 500);
if (!isProduction) {
/* development error handler will print stacktrace */
res.json({errors: {
message: err.message,
error: err.err,
stack: err.stack
}});
} else {
/* production error handler no stacktraces leaked to user */
res.json({errors: {
message: err.message,
error: {},
stack: {}
}});
}
}
};
module.exports = exceptionHandler;