From 908f06415073bcf76b20af74ddb2f3f2e18c1cf9 Mon Sep 17 00:00:00 2001 From: Piotr Date: Tue, 13 Apr 2021 10:59:17 +0200 Subject: [PATCH] Update productController.js If product is not found, not error is thrown. --- mongoosedemo/productController.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mongoosedemo/productController.js b/mongoosedemo/productController.js index dd5adb2..434dbc2 100644 --- a/mongoosedemo/productController.js +++ b/mongoosedemo/productController.js @@ -51,10 +51,13 @@ router.put('/products/:id',(req,res)=>{ }) router.delete('/products/:id',(req,res)=>{ - Product.findByIdAndDelete({_id:req.params.id},(err,result)=>{ + Product.findByIdAndDelete({_id:req.params.id},(err,product,result)=>{ if(err)console.log(err); - res.send(result); - + if(!product) { + res.status(400).send("Product not found!"); + } else { + res.send(result); + } }) })