Catching Errors Thrown by Rejected Promises
The Principle
How to Catch Promises
Catching Errors Locally
export function foo() {
return dispatch => ({
type: 'FOO_ACTION',
// Throw an error
payload: new Promise(() => {
throw new Error('foo');
})
// Catch the error locally
}).catch(error => {
console.log(error.message); // 'foo'
// Dispatch a second action in response to the error
dispatch(bar());
});
}Catching Errors Globally
The unhandledrejection Event
Last updated