mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 17:57:26 +03:00
Updated ErrorHandler so that it logs errors in production
This commit is contained in:
parent
43097b93e5
commit
701c143149
3 changed files with 11 additions and 3 deletions
|
@ -3,7 +3,7 @@ import * as PropTypes from 'prop-types';
|
||||||
import './ErrorHandler.scss';
|
import './ErrorHandler.scss';
|
||||||
import { Button } from 'reactstrap';
|
import { Button } from 'reactstrap';
|
||||||
|
|
||||||
const ErrorHandler = ({ location }) => class ErrorHandler extends React.Component {
|
const ErrorHandler = ({ location }, { error }) => class ErrorHandler extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
children: PropTypes.node.isRequired,
|
children: PropTypes.node.isRequired,
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,12 @@ const ErrorHandler = ({ location }) => class ErrorHandler extends React.Componen
|
||||||
return { hasError: true };
|
return { hasError: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidCatch(e) {
|
||||||
|
if (process.env.NODE_ENV !== 'development') {
|
||||||
|
error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.state.hasError) {
|
if (this.state.hasError) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -7,6 +7,7 @@ import ErrorHandler from '../ErrorHandler';
|
||||||
|
|
||||||
const provideServices = (bottle, connect, withRouter) => {
|
const provideServices = (bottle, connect, withRouter) => {
|
||||||
bottle.constant('window', global.window);
|
bottle.constant('window', global.window);
|
||||||
|
bottle.constant('console', global.console);
|
||||||
|
|
||||||
bottle.serviceFactory('ScrollToTop', ScrollToTop, 'window');
|
bottle.serviceFactory('ScrollToTop', ScrollToTop, 'window');
|
||||||
bottle.decorator('ScrollToTop', withRouter);
|
bottle.decorator('ScrollToTop', withRouter);
|
||||||
|
@ -31,7 +32,7 @@ const provideServices = (bottle, connect, withRouter) => {
|
||||||
|
|
||||||
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
||||||
|
|
||||||
bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window');
|
bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window', 'console');
|
||||||
};
|
};
|
||||||
|
|
||||||
export default provideServices;
|
export default provideServices;
|
||||||
|
|
|
@ -9,10 +9,11 @@ describe('<ErrorHandler />', () => {
|
||||||
reload: jest.fn(),
|
reload: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const console = { error: jest.fn() };
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const ErrorHandler = createErrorHandler(window);
|
const ErrorHandler = createErrorHandler(window, console);
|
||||||
|
|
||||||
wrapper = shallow(<ErrorHandler children={<span>Foo</span>} />);
|
wrapper = shallow(<ErrorHandler children={<span>Foo</span>} />);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue