简体   繁体   中英

Redux Dev Tools how to include the state export with Bugsnag error

Doing a Google search didn't yield any results based on what I was searching, but I'm wondering if it would be possible to include the state snapshot you can get out of the Redux Dev Tools export when an error is sent to bugsnag?

I haven't worked with the Redux Dev Tools in any other fashion than the UI so if there is an API that I haven't found please point me in that direction and I can do some self discovery!

I don't think you can programmatically access the DevTools (especially since they're primarily a browser extension). However, your own code can absolutely access the current store state and include that in a bug report sent to the server, just like any other API call would. Just call store.getState() , get the state value, and do something with it.

There's a lot of existing logging/reporting addons available , and you might want to look at some of the articles in the Redux Techniques#Debugging section of my React/Redux links list as well.

@markerikson is correct there are several simple third party libraries that do it by adding a middleware that reports whenever there is an error thown during an action dispatch. You could use one of those or look at the source to see how to build your own. Here is the relevant source from https://github.com/netguru/redux-bugsnag-middleware/blob/master/index.js.es6#L29-L44

That library has not been updated for a while so it might be best to make your own middleware and use that one as reference.

Agreed with both @markerison and @christian-schlensker about using simple third-party libraries.

From there, I suggest sending that information in as Metadata to have it included in all your error reports in Bugsnag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM