The catch method will always run when a promise is rejected

//Promises in ES6 - Basic Setup - Chaining Promises - Conditionally Reject

function waitToResolve(seconds) {
  return new Promise(function(resolve, reject) {
    if (seconds > 2 ) {
      reject('Rejected promis > 2')
    } else {
     setTimeout(function() {
      seconds++;
      resolve(seconds);
    }, 1000);
   }
  });
}


waitToResolve(3)
  .then(waitToResolve)
  .then(function(seconds) {
  console.log(seconds)
})
  .catch(function(error) {
  console.log(error);
});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Last Updated: 8/11/2019, 10:51:29 PM