| Total Complexity | 5 |
| Complexity/F | 1.67 |
| Lines of Code | 43 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 72.72% |
| Changes | 0 | ||
| 1 | import React from 'react'; |
||
| 2 | import * as PropTypes from 'prop-types'; |
||
| 3 | import './ErrorHandler.scss'; |
||
| 4 | import { Button } from 'reactstrap'; |
||
| 5 | |||
| 6 | 2 | const ErrorHandler = ({ location }, { error }) => class ErrorHandler extends React.Component { |
|
| 7 | 2 | static propTypes = { |
|
| 8 | children: PropTypes.node.isRequired, |
||
| 9 | }; |
||
| 10 | |||
| 11 | constructor(props) { |
||
| 12 | 2 | super(props); |
|
| 13 | 2 | this.state = { hasError: false }; |
|
| 14 | } |
||
| 15 | |||
| 16 | static getDerivedStateFromError() { |
||
| 17 | return { hasError: true }; |
||
| 18 | } |
||
| 19 | |||
| 20 | componentDidCatch(e) { |
||
| 21 | 2 | if (process.env.NODE_ENV !== 'development') { |
|
| 22 | error(e); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | render() { |
||
| 27 | 3 | if (this.state.hasError) { |
|
| 28 | 1 | return ( |
|
| 29 | <div className="error-handler"> |
||
| 30 | <h1>Oops! This is awkward :S</h1> |
||
| 31 | <p>It seems that something went wrong. Try refreshing the page or just click this button.</p> |
||
| 32 | <br /> |
||
| 33 | <Button outline color="primary" onClick={() => location.reload()}>Take me back</Button> |
||
| 34 | </div> |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | 2 | return this.props.children; |
|
| 39 | } |
||
| 40 | }; |
||
| 41 | |||
| 42 | export default ErrorHandler; |
||
| 43 |