Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3364 | Rev 3451 | 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
 
3364 stevensc 4
import { addNotification } from '@app/redux/notification/notification.actions'
1197 stevensc 5
 
6
class ErrorBoundary extends React.Component {
2209 stevensc 7
  constructor(props) {
8
    super(props)
9
    this.state = { hasError: false }
10
  }
11
 
12
  static getDerivedStateFromError() {
13
    return { hasError: true }
14
  }
15
 
2205 stevensc 16
  componentDidCatch(error, errorInfo) {
2209 stevensc 17
    console.error('ErrorBoundary caught an error: ', error, errorInfo)
3407 stevensc 18
    this.props.addNotification({
19
      style: 'danger',
20
      msg: 'Ha ocurrido un error en el inicio de sesión'
21
    })
22
    if (error.message.includes('sesión')) {
23
      window.localStorage.removeItem('jwt')
24
      window.location.reload()
25
    }
1606 stevensc 26
  }
27
 
1197 stevensc 28
  render() {
29
    return this.props.children
30
  }
31
}
32
 
2209 stevensc 33
const mapDispatchToProps = {
3407 stevensc 34
  addNotification: (notification) => addNotification(notification)
2209 stevensc 35
}
36
 
37
export default connect(null, mapDispatchToProps)(ErrorBoundary)