January 2018
Beginner
658 pages
13h 10m
English
To fix the error, we can remove both of our error handlers from both the then calls, and replace them with a call at the very bottom, to a different method, which we'll call .catch:
asyncAdd(5, '7').then((res) => { console.log('Result:', res); return asyncAdd(res, 33);}).then((res) => { console.log('Should be 45', res);}).catch;
The catch promise method is similar to then, but it just takes one function. This is the error handler. As shown in the following code, we can specify one error handler if any of our promise calls fail. We'll take errorMessage and print it to the screen using console.log(errorMessage):
asyncAdd(5, '7').then((res) => { console.log('Result:', res); return asyncAdd(res, 33);}).then((res) => { console.log('Should ...