bcherny / undux

⚡️ Dead simple state for React. Now with Hooks support.
https://undux.org
MIT License
1.49k stars 31 forks source link

How to catch errors for all store subscriptions? #136

Closed negebauer closed 9 months ago

negebauer commented 3 years ago

Hi!

How can I react to an error throw inside any subscription the store? For example if I have

store.on('key').subscribe(() => {
  throw new Error('foo')
})

How could I capture that error? (not inside the subscribe code, but in general for the whole store)

bcherny commented 9 months ago

There is no way to do this generically. You could wrap your code in a try/catch if you like.