2021-05-10 18:47:26 +03:00
|
|
|
const ErrorResponse = require('../utils/ErrorResponse');
|
2021-05-17 19:26:01 +03:00
|
|
|
const colors = require('colors');
|
2021-05-10 18:47:26 +03:00
|
|
|
|
|
|
|
const errorHandler = (err, req, res, next) => {
|
|
|
|
let error = { ...err };
|
|
|
|
error.message = err.message;
|
|
|
|
|
2021-05-22 20:04:34 +03:00
|
|
|
// if (error.errors[0].type === 'unique violation') {
|
|
|
|
// const msg = error.errors[0].message;
|
|
|
|
// error = new ErrorResponse(`Field ${msg}`, 400);
|
|
|
|
// }
|
2021-05-17 19:26:01 +03:00
|
|
|
|
|
|
|
console.log(error);
|
2021-06-07 14:40:51 +03:00
|
|
|
console.log(`${err}`);
|
2021-05-10 18:47:26 +03:00
|
|
|
|
|
|
|
res.status(err.statusCode || 500).json({
|
|
|
|
success: false,
|
|
|
|
error: error.message || 'Server Error'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = errorHandler;
|