0

My application makes multiple api calls at a time from different actions. Suppose 4/12 actions give error response, Store needs to get update with all error messages(An array of 4 error messages). Finally I need to display all 4 errors popups at header. I heard of redux catch. Can anyone explain with sample code.

1

1 Answer 1

2

If you are using middleware,

import { createStore, applyMiddleware } from 'redux';

import reduxCatch from 'redux-catch';

import reducer from './reducer';

function errorHandler(error, getState, lastAction, dispatch) {
  console.error(error);
  console.debug('current state', getState());
  console.debug('last action was', lastAction);
  // optionally dispatch an action due to the error using the dispatch parameter
}

const store = createStore(reducer, applyMiddleware(
  reduxCatch(errorHandler)
));

See detailed doc on Redux-catch.

Also, check these questions:

redux-promise with Axios, and how do deal with errors?

Best practice to handle errors in Redux and React

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.