Rev 3362 | Rev 3407 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
import { connect } from 'react-redux'
import { addNotification } from '@app/redux/notification/notification.actions'
import { logout } from '@app/redux/auth/auth.actions'
class ErrorBoundary extends React.Component {
constructor(props) {
super(props)
this.state = { hasError: false }
}
static getDerivedStateFromError() {
return { hasError: true }
}
componentDidCatch(error, errorInfo) {
console.error('ErrorBoundary caught an error: ', error, errorInfo)
this.props.addNotification({ style: 'danger', msg: error.message })
if (error.message.includes('sesión')) this.props.logout()
}
render() {
return this.props.children
}
}
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification),
logout: () => logout()
}
export default connect(null, mapDispatchToProps)(ErrorBoundary)