Skip to content

Instantly share code, notes, and snippets.

@rhyek
Created May 21, 2018 18:35
Show Gist options
  • Save rhyek/d73b96afff84018f7cb25b35316cdb8e to your computer and use it in GitHub Desktop.
Save rhyek/d73b96afff84018f7cb25b35316cdb8e to your computer and use it in GitHub Desktop.
sentry error boundary
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