I need to check if the user is present in two databases and if not present, I have to create a new user.
Check if the user is present in the database 1. If it is present throw a "user exists" and catch it without executing the rest of the other then().
Check if the user is present in the database 2. If it is present throw a "user exists" and catch it without executing the rest of the other then().
Else if it is not present, create the user.
I was trying to break a promise chain. Here is the scenario. So what I did is
const promise = new Promise((resolve, reject) => {
resolve(false);
}).then(value => {
//check if user exists in table 1 and set value to True or False
if (value==True){
throw "User exists";
}
else{
return value;
}
}).then(value=> {
////check if user exists in table 2 and set value to True or False
if (value==True){
throw "User exists";
}
else{
return value;
}
}).catch(err => {
console.log(err);
});
This is how it looked briefly.
But it doesn't stop executing the later then() statements even if i throw a message. It keeps on executing the entire code even if the user is found.
And it also shows the below and stops the entire execution.
throw 'user found'
^
Note: There is something I have to do with the user values after i get them. So the execution should not be stopped.