ctrlplusb / react-async-component

Resolve components asynchronously, with support for code splitting and advanced server side rendering use cases.
MIT License
1.45k stars 62 forks source link

Exception logging using Sentry.io #29

Closed kennethtruong closed 6 years ago

kennethtruong commented 7 years ago

Just wondering what do you recommend if I wanted to log exceptions using Sentry. The async components are catching the exception so I'm wondering is there a way to pass a handler to know when an error occurred. Or maybe are we able to get an option to not catch the exceptions?

ctrlplusb commented 6 years ago

Hi @kennethtruong

You could add your own wrappers to your promises that first catch, log, then rethrow the errors.

asyncComponent(() => ({
  resolve: () => Promise.reject('💩')
    .catch((err) => { 
      logToSentry(err)
      throw err
   })
})

That's just an off the hand example, but you create a utility function to do the boilerplate for you.