aboutsummaryrefslogtreecommitdiff
path: root/server/controllers/products.js
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-29 22:32:34 +0200
committerMateja <mail@matejamaric.com>2021-07-29 22:32:34 +0200
commit6467c01cddf7333ff96de21b9ffe830c0d9bc7e4 (patch)
tree2f1e7ded2692fa9f1f51e2b6a145ba5edd1f33ca /server/controllers/products.js
parent104948f25ed38ef2ee354b271fb2368dca1b6c4d (diff)
downloadmevn-ecommerce-6467c01cddf7333ff96de21b9ffe830c0d9bc7e4.tar.gz
mevn-ecommerce-6467c01cddf7333ff96de21b9ffe830c0d9bc7e4.zip
Added status codes to more API endpoints.
This should fix login bug on client where it sets empty token when bad password is provided.
Diffstat (limited to 'server/controllers/products.js')
-rw-r--r--server/controllers/products.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/server/controllers/products.js b/server/controllers/products.js
index e039dac..12a2340 100644
--- a/server/controllers/products.js
+++ b/server/controllers/products.js
@@ -25,7 +25,7 @@ module.exports = {
const newProduct = new Product(newProductObj);
newProduct.save()
.then(() => res.json({status: "Product successfully added!"}))
- .catch(error => res.json({
+ .catch(error => res.status(400).json({
status: "Couldn't add product!",
error
}));
@@ -44,7 +44,7 @@ module.exports = {
Product.findOneAndUpdate({_id: req.params.id}, {$set: updatedProduct}, {new: true}, (error, product) => {
if (error)
- res.json({status: "Couldn't update product!", error});
+ res.status(400).json({status: "Couldn't update product!", error});
else
res.json({status: "Successfully updated product!", product});
});
@@ -53,7 +53,7 @@ module.exports = {
destroy(req, res) {
Product.findByIdAndRemove(req.params.id, (error, product) => {
if (error)
- res.json({status: "Error when removing product!", error});
+ res.status(400).json({status: "Error when removing product!", error});
else
res.json({status: "Product successfully removed!", product})
});