I have code similar to this:
promise_function().then(()=>{
//do something
return another_promise_fucntion();
}).then(() => {
//do something
return another_promise_function1();
}).then((result) => {
//check if result is valid
if(!result)
//break chain (how to stop calling the next .then functions ?)
else
return another_promise_function2();
}).then(()=>{
//do something
return another_promise_function3();
}).catch((err)=>{
//handle error
});
I want to stop calling the following .then () functions if the return result is invalid.
I used "throw new Error ()" and it worked fine, but I'm not sure if this is the recommended way.
source
share