mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
36 lines
733 B
JavaScript
36 lines
733 B
JavaScript
|
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
|