mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-08 17:27:32 +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 { Button } from 'reactstrap';
|
||||
|
||||
const ErrorHandler = ({ location }) => class ErrorHandler extends React.Component {
|
||||
const ErrorHandler = ({ location }, { error }) => class ErrorHandler extends React.Component {
|
||||
static propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
};
|
||||
|
@ -17,6 +17,12 @@ const ErrorHandler = ({ location }) => class ErrorHandler extends React.Componen
|
|||
return { hasError: true };
|
||||
}
|
||||
|
||||
componentDidCatch(e) {
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
error(e);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
|
|
|
@ -7,6 +7,7 @@ import ErrorHandler from '../ErrorHandler';
|
|||
|
||||
const provideServices = (bottle, connect, withRouter) => {
|
||||
bottle.constant('window', global.window);
|
||||
bottle.constant('console', global.console);
|
||||
|
||||
bottle.serviceFactory('ScrollToTop', ScrollToTop, 'window');
|
||||
bottle.decorator('ScrollToTop', withRouter);
|
||||
|
@ -31,7 +32,7 @@ const provideServices = (bottle, connect, withRouter) => {
|
|||
|
||||
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
||||
|
||||
bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window');
|
||||
bottle.serviceFactory('ErrorHandler', ErrorHandler, 'window', 'console');
|
||||
};
|
||||
|
||||
export default provideServices;
|
||||
|
|
|
@ -9,10 +9,11 @@ describe('<ErrorHandler />', () => {
|
|||
reload: jest.fn(),
|
||||
},
|
||||
};
|
||||
const console = { error: jest.fn() };
|
||||
let wrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
const ErrorHandler = createErrorHandler(window);
|
||||
const ErrorHandler = createErrorHandler(window, console);
|
||||
|
||||
wrapper = shallow(<ErrorHandler children={<span>Foo</span>} />);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue