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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.