-
-
Save rhyek/d73b96afff84018f7cb25b35316cdb8e to your computer and use it in GitHub Desktop.
sentry error boundary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { connect } from 'react-redux' | |
import Raven from 'raven-js'; | |
Raven.config(process.env.SENTRY_URL).install() | |
type Props = { | |
children: any, | |
user: any | |
} | |
class SentryErrorBoundary extends React.Component<Props> { | |
componentDidCatch = (error, info) => { | |
const { user } = this.props | |
if (process.env.SENTRY_ENABLED === 'true') { | |
if (user) { | |
console.log(user) | |
Raven.setUserContext({ | |
id: user._id, | |
email: user.email, | |
}) | |
} | |
Raven.captureException(error, { extra: info }) | |
} | |
} | |
render() { | |
return this.props.children | |
} | |
} | |
const mapStateToProps = state => ({ | |
user: state.auth.user | |
}) | |
export default connect(mapStateToProps)(SentryErrorBoundary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment