If the chain of promises:

Promise(function(resolve, reject) {...})) .then(function() {return [Новый проимс]}) .then(function() {return [Новый проимс]}) .then(function() {return [Новый проимс]}) ΠΈ Ρ‚.Π΄. 

You need to be able to interrupt it and, for example, start the function that creates the promise again, or any other preceding it does not matter. I do not use reject yet, in case of error I do resolve (0). Yes, and reject does not solve the problem:

 Promise(function(resolve, reject) {reject();})) .then(function() {return [Новый проимс]}, function() {[Ошибка]}) // Π—Π΄Π΅ΡΡŒ ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ ΠΎΡˆΠΈΠ±ΠΊΡƒ .then(function() {return [Новый проимс]}) // Код ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ Π² любом случаС 

So far I see only this solution: in case of an error, do resolve (0) and at every stage do a check, pushing the error to the end:

 .then(function(rez) { if(!rez) {[Запуск Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠŸΡ€ΠΈ ОшибкС]; return rez;} else {return [Новый проимс]} }) .then(function(rez) { if(!rez) {[Запуск Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠŸΡ€ΠΈ ОшибкС]; return rez;} else {return [Новый проимс]} }) 

But this is an extra code. How to make the next .then just not work?

    1 answer 1

    In vain you do not use reject - it does exactly what you need.

    And in order to handle the error - but leave it as an error - you must use the return Promise.reject(...) or throw ... in the error handler:

     new Promise(function(_, reject) { reject(); }) .then(function() { console("ok") }, function() { console.log("rejected"); return Promise.reject(); }) .then(function() { console("ok") }) .then(function() { console("ok") }, function() { console.log("rejected"); return Promise.reject(); }) // Π²Ρ‹Π²ΠΎΠ΄: // rejected // rejected