3
votes

If a js error occurs as the result of an emitted action from a redux-observable epic then it stops all epics from listening to new actions. This is pretty nasty since on the front-end it still appears as if the app is working but in the background nothing is getting saved.

I tried catching the error in my epic but for some reason it doesn't catch errors that are caused by the resulting emitted action (see example here: https://stackblitz.com/edit/redux-observable-playground-qtughj?file=ping-pong.js)

I thought that upgrading to version 1.0.0 redux-observable could fix the issue but unfortunately it remains.

Is there any way that errors caused by a redux-observable emitted action can be caught?

The issue is different than this question since the error is getting triggered in a reducer that occurs after the epic has emitted it's output redux action so catching it with .error in the chain of observables doesn't work (see example above for a demo).

Thanks!

1

1 Answers

2
votes

After discussing this issue in the redux-observable Github repo the safest solution seems to be to create some custom Redux middleware to stop the error from bubbling all the way back up to the root epic e.g.

const store = createStore(rootReducer,
  applyMiddleware(epicMiddleware, store => next => action => {
    try {
      next(action);
    } catch (e) {
      setTimeout(() => {
        throw e;
      });
    }
  })
);