Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2284 | Rev 3364 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1197 stevensc 1
import React from 'react'
2
import { connect } from 'react-redux'
1202 stevensc 3
 
3362 stevensc 4
import { logout } from '@store/auth/auth.actions'
5
import { addNotification } from '@store/notification/notification.actions'
1197 stevensc 6
 
7
class ErrorBoundary extends React.Component {
2209 stevensc 8
  constructor(props) {
9
    super(props)
10
    this.state = { hasError: false }
11
  }
12
 
13
  static getDerivedStateFromError() {
14
    return { hasError: true }
15
  }
16
 
2205 stevensc 17
  componentDidCatch(error, errorInfo) {
2209 stevensc 18
    console.error('ErrorBoundary caught an error: ', error, errorInfo)
19
    this.props.addNotification({ style: 'danger', msg: error.message })
2284 stevensc 20
    if (error.message.includes('sesión')) this.props.logout()
1606 stevensc 21
  }
22
 
1197 stevensc 23
  render() {
24
    return this.props.children
25
  }
26
}
27
 
2209 stevensc 28
const mapDispatchToProps = {
2284 stevensc 29
  addNotification: (notification) => addNotification(notification),
30
  logout: () => logout()
2209 stevensc 31
}
32
 
33
export default connect(null, mapDispatchToProps)(ErrorBoundary)