1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-sentry/components/withSentry.js

36 lines
733 B
JavaScript
Raw Normal View History

import React from 'react'
import Raven from 'raven-js'
const SENTRY_DSN = ''
function withSentry (Child) {
return class WrappedComponent extends React.Component {
static getInitialProps (context) {
if (Child.getInitialProps) {
return Child.getInitialProps(context)
}
return {}
}
constructor (props) {
super(props)
this.state = {
error: null
}
Raven.config(
SENTRY_DSN
).install()
}
componentDidCatch (error, errorInfo) {
this.setState({ error })
Raven.captureException(error, { extra: errorInfo })
}
render () {
return <Child {...this.props} error={this.state.error} />
}
}
}
export default withSentry