mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-22 17:51:30 +03:00
22 lines
553 B
JavaScript
22 lines
553 B
JavaScript
const ErrorResponse = require('../utils/ErrorResponse');
|
|
const colors = require('colors');
|
|
|
|
const errorHandler = (err, req, res, next) => {
|
|
let error = { ...err };
|
|
error.message = err.message;
|
|
|
|
// if (error.errors[0].type === 'unique violation') {
|
|
// const msg = error.errors[0].message;
|
|
// error = new ErrorResponse(`Field ${msg}`, 400);
|
|
// }
|
|
|
|
console.log(error);
|
|
console.log(`${err}`);
|
|
|
|
res.status(err.statusCode || 500).json({
|
|
success: false,
|
|
error: error.message || 'Server Error'
|
|
})
|
|
}
|
|
|
|
module.exports = errorHandler; |