-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: * moved the configuration from HOC to `_app.js` * fixed the example, as `componentDidCatch` catches errors during rendering phase, but not within event handlers.
- Loading branch information
1 parent
bd3f65b
commit b1459bf
Showing
3 changed files
with
28 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import App from 'next/app' | ||
import Raven from 'raven-js' | ||
|
||
const SENTRY_PUBLIC_DSN = '' | ||
|
||
export default class MyApp extends App { | ||
constructor (...args) { | ||
super(...args) | ||
Raven.config(SENTRY_PUBLIC_DSN).install() | ||
} | ||
|
||
componentDidCatch (error, errorInfo) { | ||
Raven.captureException(error, { extra: errorInfo }) | ||
|
||
// This is needed to render errors correctly in development / production | ||
super.componentDidCatch(error, errorInfo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import React from 'react' | ||
import withSentry from '../components/withSentry' | ||
|
||
class Index extends React.Component { | ||
static getInitialProps (context) { | ||
const { isServer } = context | ||
return { isServer } | ||
state = { | ||
raiseError: false | ||
} | ||
|
||
onClickHandler () { | ||
throw new Error('woops') | ||
componentDidUpdate () { | ||
if (this.state.raiseError) { | ||
throw new Error('Houston, we have a problem') | ||
} | ||
} | ||
|
||
raiseError = () => this.setState({ raiseError: true }) | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<h2>Index page</h2> | ||
|
||
<button onClick={this.onClickHandler.bind(this)}>Click to raise error</button> | ||
<button onClick={this.raiseError}>Click to raise the error</button> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default withSentry(Index) | ||
export default Index |