Answer the question
In order to leave comments, you need to log in
How to catch various rejects in a promise and break the chain?
Please tell me, I'm confused.
Suppose there is some function that returns various states. One state - everything is ok, and different views when something went wrong. You need to run the handler for this state and exit the chain.
function p1(inputData) {
return new Promise((resolve, reject) => {
switch(inputData) {
case SUCCESS_0:
resolve("Success 0");
break;
case ERROR_0:
reject("Reason 0");
break;
case ERROR_1:
reject("Reason 1");
break;
case ERROR_2:
reject("Reason 2");
break;
}
});
}
p1(inputData)
.catch(ERROR_0, () => processError_0()) //и выйти из цепочки
.catch(ERROR_1, () => processError_1()) //и выйти из цепочки
.catch(ERROR_2, () => processError_2()) //и выйти из цепочки
.then(ifSuccess_0()); //только если не вылезла ошибка в p1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question