handle error in promise chain 1

handle error in promise chain

promise.then(successHandler).catch(errorHandler);

Here is what the above code is Doing:
1. We’re creating a new Promise object.
2. We’re passing a function to the Promise object.
3. The function takes two arguments: resolve and reject.
4. We’re calling the resolve function after 2 seconds.
5. We’re calling the reject function after 4 seconds.
6. We’re calling the then method on the promise object.
7. We’re passing a success handler function to the then method.
8. We’re calling the catch method on the promise object.
9. We’re passing an error handler function to the catch method.

Similar Posts