How should I stop the promise chain in this case? Execute the code of second then only when the condition in the first then is true.
var p = new Promise((res
You could read the documentation, which says
Promise.thenreturn a rejected Promise if the input function throws an error, or the input function returns a rejected Promise.
If you prefer, you could read the Promise A spec, in the section about then, where promise2 refers to the resulting promise:
If either
onFulfilledoronRejectedthrows an exceptione,promise2must be rejected with e as the reason.)
If you prefer, you could read the excellent 2ality blog:
then()returns a new promise Q (created via the constructor of the receiver): If either of the reactions returns a value, Q is resolved with it. If either of the reactions throws an exception, Q is rejected with it.
You could read the brilliant YDKJS:
A thrown exception inside either the fulfillment or rejection handler of a then(..) call causes the next (chained) promise to be immediately rejected with that exception.