Small fixes
This commit is contained in:
parent
adc4aaed0f
commit
4510a709d4
2 changed files with 10 additions and 3 deletions
|
@ -20,7 +20,7 @@ exports.createPair = asyncWrapper(async (req, res, next) => {
|
||||||
exports.getAllPairs = asyncWrapper(async (req, res, next) => {
|
exports.getAllPairs = asyncWrapper(async (req, res, next) => {
|
||||||
const pairs = await Config.findAll();
|
const pairs = await Config.findAll();
|
||||||
|
|
||||||
res.status(201).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
data: pairs
|
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));
|
return next(new ErrorResponse(`Key ${req.params.key} was not found`, 404));
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(201).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
data: pair
|
data: pair
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
const ErrorResponse = require('../utils/ErrorResponse');
|
const ErrorResponse = require('../utils/ErrorResponse');
|
||||||
|
const colors = require('colors');
|
||||||
|
|
||||||
const errorHandler = (err, req, res, next) => {
|
const errorHandler = (err, req, res, next) => {
|
||||||
let error = { ...err };
|
let error = { ...err };
|
||||||
error.message = err.message;
|
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({
|
res.status(err.statusCode || 500).json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|
Loading…
Reference in a new issue