Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Javascript promise chaining not working as expected. After going inside catch block it is still throwing error

$
0
0

I have tried to implement promise chaining in Javascript with 3 simple promises. First promise I am resolving and last 2 I am rejecting. Till 2nd rejection it is working fine. But after the catch statement it is throwing error again for 3rd promise. I want to use only one catch block.

var promise1 = new Promise((resolve, reject) => resolve("1st resolved"));var promise2 = new Promise((resolve, reject) => reject("2nd rejected"));var promise3 = new Promise((resolve, reject) => reject("3rd rejected"));// promise chainingpromise1  .then((res) => {    console.log(res);    return promise2;  })  .then((res) => {    console.log(res);    return promise3;  })  .then((res) => {    console.log(res);  })  .catch((err) => console.log("error in promise", err));

I have attached the error alsoPlease refer this for error - (https://i.sstatic.net/pQ9wE5fg.png)


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>