Passed
Pull Request — master (#163)
by Alejandro
06:15
created

src/common/ErrorHandler.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 43
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 5
eloc 33
mnd 2
bc 2
fnc 3
dl 0
loc 43
ccs 8
cts 11
cp 0.7272
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ErrorHandler.js ➔ componentDidCatch 0 4 2
A ErrorHandler.js ➔ getDerivedStateFromError 0 3 1
A ErrorHandler.js ➔ render 0 14 2
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