Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | // @flow
import * as React from 'react';
import {Alert} from 'antd';
import { FormattedMessage } from 'react-intl';
import type {HOCProps} from './types';
type State = {
error: any,
errorInfo: any
};
export default function errorCatch(Com: React.ComponentType<*>) {
return class ComponentErrorCatch extends React.Component<HOCProps, State> {
state = {
error: false,
errorInfo: {componentStack: null}
}
componentDidCatch(e: Error, info: Object) {
// eslint-disable-next-line
console.log(e, info);
this.setState({
error: e,
errorInfo: info
});
}
render() {
const {error} = this.state;
if (error) {
return <Alert
message={<FormattedMessage id="hocs.errorCatch.message" />}
type="error"
closable
closeText={
<FormattedMessage id="hocs.errorCatch.refresh" />
}
afterClose={() => location.reload()}
/>
}
return <Com {...this.props} />
}
};
} |