mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-21 09:11:29 +03:00
23 lines
630 B
JavaScript
23 lines
630 B
JavaScript
const ErrorResponse = require('../utils/ErrorResponse');
|
|
const colors = require('colors');
|
|
const Logger = require('../utils/Logger');
|
|
const logger = new Logger();
|
|
|
|
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);
|
|
// }
|
|
|
|
logger.log(error.message.split(',')[0], 'ERROR');
|
|
|
|
res.status(err.statusCode || 500).json({
|
|
success: false,
|
|
error: error.message || 'Server Error'
|
|
})
|
|
}
|
|
|
|
module.exports = errorHandler; |