Is Nesting Promises Bad Practice?

I know that my code has the correct logic, but everywhere I look, they tell me not to use nested promises. Is this a precedent for nested promises?

The logic is as follows:

  • promise1 fails → reverse promise1

  • success1 successfully → promise2 / prom3 does not work → reverse promise1, promise2, promise 3

  • promise1 is successful → promise2 and promise3 is successful

    let data = null;
    promise1.then((response) => {
        data = response;
        return Promise.all([promise2(), proimse3()])
            .catch((error) => {
                //Reverse only promise2, promise3
                //Throw error to reverse promise1
            });
    }).then((id) => {
        something(data);
    }).catch((error) => {
        //Reverse only promise1
    });
    
+4
source share

Source: https://habr.com/ru/post/1681237/


All Articles