Newer Version Available

This content describes an older version of this product. View Latest

Error Handling with Promises

Promises can simplify code that handles the success or failure of asynchronous calls. To use error handling with promises, use the catch() method on the promise that is returned from calling an API method.

The catch() method returns a promise and accepts a single function parameter that’s called if the promise is rejected. This function has one argument that shows the reason for the rejection. The promise returned by catch() is rejected if the function that is passed in either throws an error or returns a promise that’s rejected. Otherwise, the promise is resolved.