Here is My code,i just started learning Promises, trying to Handle the error using promise Catch blocks, is there any way to handle both errors using only one catch block, in my code i am using two catch blocks to handle the errors. can any bdy help me on this.
exports.create = function (req, res) {
DetailsValidator.validator.keyValidator(req.body).then(success=>{
return true
}).then((result)=>{
console.log("coming Body is", req.body);
let acount = new CloudAccountDetailSchema();
acount.type = 1;// For Aws its type is one
acount.owner = 212;
acount.projectId = req.query.pId;
acount.save().then(accountDetail=> {
res.status(201).json({
success: true,
data: {
message: " account successfully added"
}
})
}).catch((e)=>{
return res.status(409).send({
success: false,
message: e
});
})
}).catch(err => {
return res.status(409).send({
success: false,
message: err
});
})
};