mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
a35e747e24
* Added Sentry example * Code style fixes * Fixes docs + removed demo DSN + send error to comp
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
|