Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(errors): errors from reducers are no longer caught and logged, in…
…stead are rethrown. related #263#issuecomment-395109222

BREAKING CHANGE: For 0.19.0 errors from reducers are no longer caught and console.error logged, instead they are just rethrown as before. This was a temporary workaround for a bug in rxjs where it would silently swallow errors. That bug has been fixed in 5.5.6+, so it is highly recommended you use _at least_ rxjs@5.5.6+ with this version of redux-observable. However, redux-observable is close to reaching 1.0.0-final which will require rxjs v6 and redux v4, if you'd like to start upgrading to it now you can use redux-observable@next (as of this writing 1.0.0-beta.1)
  • Loading branch information
jayphelps committed Jun 6, 2018
1 parent f632eaa commit f90f8ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
8 changes: 1 addition & 7 deletions src/createEpicMiddleware.js
Expand Up @@ -53,13 +53,7 @@ export function createEpicMiddleware(rootEpic, options = defaultOptions) {
return output$;
})
::switchMap(output$ => options.adapter.output(output$))
.subscribe(action => {
try {
store.dispatch(action);
} catch (err) {
console.error(err);
}
});
.subscribe(store.dispatch);

// Setup initial root epic
epic$.next(rootEpic);
Expand Down
12 changes: 5 additions & 7 deletions test/createEpicMiddleware-spec.js
Expand Up @@ -70,13 +70,11 @@ describe('createEpicMiddleware', () => {
]);
});

it('should console error when reducer throw exception', () => {
sinon.spy(console, 'error');

it('should rethrow errors when a reducer throws an exception', () => {
const reducer = (state = [], action) => {
switch (action.type) {
case 'ACTION_1':
throw new Error();
throw new Error('bad stuff');
default:
return state;
}
Expand All @@ -89,9 +87,9 @@ describe('createEpicMiddleware', () => {
const middleware = createEpicMiddleware(epic);
const store = createStore(reducer, applyMiddleware(middleware));

store.dispatch({ type: 'FIRE_1' });
expect(console.error.callCount).to.equal(1);
console.error.restore();
expect(() => {
store.dispatch({ type: 'FIRE_1' });
}).to.throw(Error, 'bad stuff');
});

it("should throw if you don't provide a rootEpic", () => {
Expand Down

0 comments on commit f90f8ef

Please sign in to comment.