Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update with-sentry example #4859

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 0 additions & 35 deletions examples/with-sentry/components/withSentry.js

This file was deleted.

18 changes: 18 additions & 0 deletions examples/with-sentry/pages/_app.js
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)
}
}
19 changes: 10 additions & 9 deletions examples/with-sentry/pages/index.js
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