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
Leandro Ardissone a35e747e24 Added Sentry.io example (#3215)
* Added Sentry example

* Code style fixes

* Fixes docs + removed demo DSN + send error to comp
2017-11-04 15:06:16 +01:00

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