const { getAnswer } = require('../utils/common'); function errorHandler(err, req, res, _next) { console.error(err); if (typeof (err) === 'string') { return res.status(400).json(getAnswer([{ message: err }])); } if (err.name === 'UnauthorizedError') { // jwt authentication error return res.status(401).json(getAnswer([{ message: 'Invalid Token' }])); } // default to 500 server error return res.status(500).json(getAnswer([{ message: err?.message || 'Invalid Token' }])); } module.exports = errorHandler;