Skip to content

Commit 879023c

Browse files
MaxBittkerkamilogorek
authored andcommitted
docs: Move redux info under react page, talk about error boundaries
1 parent 4f12c32 commit 879023c

File tree

3 files changed

+59
-73
lines changed

3 files changed

+59
-73
lines changed

docs/integrations/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ To install a plugin just include the plugin **after** Raven has been loaded and
3838
backbone
3939
ember
4040
react
41-
redux
4241
vue
4342

4443

docs/integrations/react.rst

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ React
44
Installation
55
------------
66

7-
Start by adding the ``raven.js`` script tag to your page. It should be loaded as early as possible.
7+
Start by adding the ``raven.js`` script tag to your page. It should be loaded as early as possible, before your main javascript bundle.
88

99
.. sourcecode:: html
1010

@@ -24,30 +24,68 @@ At this point, Raven is ready to capture any uncaught exception.
2424

2525
Expanded Usage
2626
--------------
27-
28-
It's likely you'll end up in situations where you want to gracefully
29-
handle errors. A good pattern for this would be to setup a logError helper:
27+
If you're using React 16 or above, `Error Boundaries <https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html>`_
28+
are an important tool for defining the behavior of your application in the face of errors. Be sure to send errors they catch to
29+
Sentry using ``Raven.captureException``, and optionally this is also a great opportunity to surface `User Feedback <https://docs.sentry.io/learn/user-feedback/>`_
3030

3131
.. code-block:: javascript
3232
33-
function logException(ex, context) {
34-
Raven.captureException(ex, {
35-
extra: context
36-
});
37-
/*eslint no-console:0*/
38-
window.console && console.error && console.error(ex);
39-
}
40-
41-
Now in your components (or anywhere else), you can fail gracefully:
42-
43-
.. code-block:: javascript
33+
class ExampleBoundary extends Component {
34+
constructor(props) {
35+
super(props);
36+
this.state = { error: null };
37+
}
38+
39+
componentDidCatch(error, errorInfo) {
40+
this.setState({ error });
41+
Raven.captureException(error, { extra: errorInfo });
42+
}
4443
45-
var Component = React.createClass({
4644
render() {
47-
try {
48-
// ..
49-
} catch (ex) {
50-
logException(ex);
45+
if (this.state.error) {
46+
//render fallback UI
47+
return (
48+
<div
49+
className="snap"
50+
onClick={() => Raven.lastEventId() && Raven.showReportDialog()}>
51+
<img src={oops} />
52+
<p>We're sorry — something's gone wrong.</p>
53+
<p>Our team has been notified, but click here fill out a report.</p>
54+
</div>
55+
);
56+
} else {
57+
//when there's not an error, render children untouched
58+
return this.props.children;
5159
}
5260
}
53-
});
61+
}
62+
63+
.. code-block:: javascript
64+
<div>
65+
<ExampleBoundary>
66+
<h2>Sidebar</h2>
67+
<Widget/>
68+
</ExampleBoundary>
69+
<p> This content won't unmount when Widget throws. </p>
70+
</div>
71+
72+
One important thing to note about the behavior of error boundaries in development mode is that React will rethrow errors they catch.
73+
This will result in errors being reported twice to Sentry with the above setup, but this won't occur in your production build.
74+
75+
Read more about error boundaries `in this blog post <https://blog.sentry.io/2017/09/28/react-16-error-boundaries>`_.
76+
77+
Redux
78+
----------------
79+
If you use `Redux <https://github.com/reactjs/redux>`_ there are some useful community maintained middleware packages
80+
for annotating error reports with useful information, such as store state and recent actions:
81+
82+
- `captbaritone/raven-for-redux <https://github.com/captbaritone/raven-for-redux>`_
83+
- `ngokevin/redux-raven-middleware <https://github.com/ngokevin/redux-raven-middleware>`_
84+
85+
Redux Sagas Middleware
86+
----------------
87+
If you're using `Redux Saga <https://github.com/redux-saga/redux-saga>`_ be
88+
aware that it does not bubble errors up to the browsers uncaught exception handler.
89+
90+
You may specify an error handler that captures saga exceptions by passing an ``onError`` function to the ``createSagaMiddleware`` options, and call ``Raven.captureException`` inside that callback.
91+
See the `Redux Saga documentation <https://redux-saga.js.org/docs/api/#createsagamiddlewareoptions>`_ for more details.

docs/integrations/redux.rst

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)