diff --git a/index.js b/index.js index 93bcd8a..fea746d 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ /* eslint-disable no-unused-vars */ import express from 'express'; import path from 'path'; +import cors from 'cors'; import bodyParser from 'body-parser'; import passport from 'passport'; import session from 'express-session'; @@ -14,6 +15,7 @@ dotenv.config(); const swaggerDocument = YAML.load('./swagger.yaml'); const app = express(); +app.use(cors()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true diff --git a/middlewares/errorHandler.js b/middlewares/errorHandler.js index d5edae1..61e2100 100644 --- a/middlewares/errorHandler.js +++ b/middlewares/errorHandler.js @@ -10,7 +10,7 @@ function ErrorHander(cb) { try { await cb(req, res, nex); } catch (err) { - return res.status(400).json({ message: err }); + return res.status(400).json({ error: err.name === 'SequelizeValidationError' ? err.message : err }); } }; }