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