Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux Saga stops after error

I'm combining a set of Sagas, ( some takeEvery and takeLatest ) from different modules and using yield all(sagas) to combine them all in RootSaga.

Everything works, without issue. I catch errors inside the Sagas themselves. But, now the requirement is to catch errors at RootSaga level too, in any case, someone misses catching a problematic part.( Actually, I'm working on boilerplate for a multi-team project. )

I see, if someone is not using try catch to catch a problematic part, then the error is propagated and Saga completely stops working after that. Sagas won't watch anything thereafter.

What I want to do is, let other Sagas run without issues and RootSaga to be working thereafter, keep watching as usual. How can I achieve this?

export default function* rootSaga() {
    yield all(sagas);
}
like image 860
Milindu Sanoj Kumarage Avatar asked Jan 03 '23 22:01

Milindu Sanoj Kumarage


2 Answers

For v1 use

rootSagaTask.toPromise().catch(e => {

});
like image 144
ladast Avatar answered Jan 14 '23 03:01

ladast


When you run the rootSaga you are getting back a task. That task has a done property which is a promise. So:

const rootSagaTask = reduxSagaMiddleware.run(rootSaga);

rootSagaTask.done.catch(error => {
  // Error here is a fatal error.
  // None of the sagas down the road caught it.
});
like image 32
Krasimir Avatar answered Jan 14 '23 05:01

Krasimir