Mise à jour de middlewares
This commit is contained in:
@@ -38,7 +38,7 @@ const auth = {
|
||||
return res.status(401).json({message: "Unauthorized - You are not allowed to access this resource.", err: err, info: info});
|
||||
}
|
||||
req.application = application;
|
||||
req.payload = {id: application.author._id};
|
||||
req.payload = {id: application.author.id};
|
||||
return next();
|
||||
})(req, res, next);
|
||||
} else {
|
||||
|
||||
@@ -4,30 +4,19 @@ if (appEnv == undefined) {
|
||||
}
|
||||
const isProduction = appEnv === 'production',
|
||||
chalk = require('chalk'),
|
||||
utils = require('../utils');
|
||||
DateUtilities = require('../utils/dateUtilities');
|
||||
|
||||
const exceptionHandler = {
|
||||
notFoundErrorHandler: (req, res, next) => {
|
||||
let err = new Error('Not Found');
|
||||
err.statusCode = 404;
|
||||
console.log(`${utils.getDateTimeISOString()}`, chalk.yellow(`${err.statusCode} - ${err.message}`));
|
||||
console.log(`${DateUtilities.getDateTimeISOString()}`, chalk.yellow(`${err.statusCode} - ${err.errorType}`));
|
||||
next(err);
|
||||
/*if (req.xhr) {
|
||||
res.status(err.statusCode).json(err);
|
||||
} else {
|
||||
next(err);
|
||||
}*/
|
||||
},
|
||||
logErrorHandler: (err, req, res, next) => {
|
||||
console.log(`${utils.getDateTimeISOString()}`, chalk.red(`Error handler : ${err.statusCode} - ${err.message}`)); // ${err.err}
|
||||
console.log(`${DateUtilities.getDateTimeISOString()}`, chalk.red(`Error handler : ${err.statusCode} - ${err.errorType}`)); // ${err.err}
|
||||
console.error(err.stack);
|
||||
next(err);
|
||||
/*if (req.xhr) {
|
||||
res.status(err.statusCode || 500).json(err);
|
||||
//res.status(err.statusCode || 500).json({statusCode: err.statusCode, message: err.message});
|
||||
} else {
|
||||
next(err);
|
||||
}*/
|
||||
},
|
||||
clientErrorHandler: (err, req, res, next) => {
|
||||
if (req.xhr) {
|
||||
@@ -43,6 +32,7 @@ const exceptionHandler = {
|
||||
/* development error handler will print stacktrace */
|
||||
res.json({errors: {
|
||||
statusCode: err.statusCode,
|
||||
errorType: err.errorType,
|
||||
message: err.message,
|
||||
//error: err.err,
|
||||
stack: err.stack
|
||||
@@ -51,6 +41,7 @@ const exceptionHandler = {
|
||||
/* production error handler no stacktraces leaked to user */
|
||||
res.json({errors: {
|
||||
statusCode: err.statusCode,
|
||||
errorType: err.errorType,
|
||||
message: err.message,
|
||||
//error: {},
|
||||
stack: {}
|
||||
|
||||
Reference in New Issue
Block a user