How to break the chain of promises?

There is here such code:
foo()
.catch(onError)
.then()
.then()
 .catch();


when foo fails, the error is in the first catch, where the onError is checked for conformance to a certain condition. possible although so that if the error is in the onError udovletvorit the chain broke and everything after the first catch should not occur. otherwise, if the error does not satisfy the condition, it will continue to move along the chain to the second catch?
March 19th 20 at 09:09
1 answer
March 19th 20 at 09:11
if the error is in the onError udovletvorit the chain broke

use throw in the catch and the chain stops
the last catch will work - Santina_Hartma commented on March 19th 20 at 09:14
Create a flag at the top. Checked first catch. Throw an exception and change the flag. In the second ketch check the flag, if it is true, do not perform the logic that you want to protect. - Nels.Denes commented on March 19th 20 at 09:17

Find more questions by tags JavaScript