-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can I setup a global error handler? #1672
Comments
Do you want to catch all uncaught exceptions? if yes you can do it like this:
|
But in this way, the rootTask has been stopped. |
Or how can I make the following code keep running even though there is an error in Api.fetch
|
@Kabike You could use the following code to let your saga automatically restart when it encounters an error: function keepAlive(sagaFn) {
return function*() {
while (true) {
try {
const result = yield io.call(sagaFn)
console.log('saga completes with result:', result)
return result
} catch (e) {
console.error('saga aborted due to:', e)
console.log('restarting the saga...')
}
}
}
}
// And your code becomes like...
yield takeEvery(actions.GET_ALL_PRODUCTS, keepAlive(getAllProducts)) You can put |
root saga restart will reset internal state of it and its child sagas |
closed as there are no action points here |
We used function similar to suggested by @Taym95
with old version "redux-saga": "^0.15.3",, but after I tried to update to the latest V1.1.1, |
sagaMiddleware.run(rootSagas, store.dispatch).toPromise().catch(e => {
logger.error({ message: e.message, source: 'sagaError', stacktrace: e.sagaStack });
}); |
I knew that exception in call effect should be catched otherwise it will propagate to parent.But I do not want to wirte the same try/catch code everywhere, so can I setup a global error handler for these kind of things.
The text was updated successfully, but these errors were encountered: