From 4510a709d41a76766571f738453a179a704bdf8c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 May 2021 18:26:01 +0200 Subject: [PATCH] Small fixes --- controllers/config.js | 4 ++-- middleware/errorHandler.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/controllers/config.js b/controllers/config.js index ff94e4f..d73bb66 100644 --- a/controllers/config.js +++ b/controllers/config.js @@ -20,7 +20,7 @@ exports.createPair = asyncWrapper(async (req, res, next) => { exports.getAllPairs = asyncWrapper(async (req, res, next) => { const pairs = await Config.findAll(); - res.status(201).json({ + res.status(200).json({ success: true, data: pairs }) @@ -38,7 +38,7 @@ exports.getSinglePair = asyncWrapper(async (req, res, next) => { return next(new ErrorResponse(`Key ${req.params.key} was not found`, 404)); } - res.status(201).json({ + res.status(200).json({ success: true, data: pair }) diff --git a/middleware/errorHandler.js b/middleware/errorHandler.js index 2b15314..b4af510 100644 --- a/middleware/errorHandler.js +++ b/middleware/errorHandler.js @@ -1,10 +1,17 @@ const ErrorResponse = require('../utils/ErrorResponse'); +const colors = require('colors'); const errorHandler = (err, req, res, next) => { let error = { ...err }; error.message = err.message; - console.log(err); + 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}`.bgRed); res.status(err.statusCode || 500).json({ success: false,