Skip to content
Advertisement

Evaluate Value at Each Step of a Chained Promise and Break Out of Promise

I have the following chained promise. At each step, I need to evaluate if the returned value is not null. I can add an if else condition at each step, but I was wondering if there is a more concise way of doing this. Also, how can I break out of the chain if the value is null at any step?

JavaScript

Advertisement

Answer

You break out of the promise chain by throwing an error:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement