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.
            Asked
            
        
        
            Active
            
        
            Viewed 2,403 times
        
    0
            
            
        - 
                    Does this answer your question? [Best practice to handle errors in Redux and React](https://stackoverflow.com/questions/40837846/best-practice-to-handle-errors-in-redux-and-react) – Michael Freidgeim May 14 '21 at 21:54
 
1 Answers
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:
        Mushfiq
        
- 759
 - 1
 - 8
 - 41