December 2017
Beginner
372 pages
10h 32m
English
The next step is to handle the response returned by the promise. The Promise API provides two functions, namely, then and catch. The then function handles the successful completion of the promise and it takes another function which should be called when the promise is resolved, as seen in the following line of code:
p.then(boards=>boards.forEach(board=>console.log(board.title)));
Here, we fetch the boards array and then loop through each element to print the title of each board. This method will be called if the promise returned successfully. To handle the error scenario, the promise API has a catch function as shown here:
p.catch(msg=>console.log(msg));
Because our reject function was passing an error message, in ...
Read now
Unlock full access