UNPKG

@doreamonjs/gate

Version:
43 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = tslib_1.__importStar(require("react")); const dva_1 = require("dva"); const components_1 = require("@doreamonjs/components"); const message = tslib_1.__importStar(require("@doreamonjs/plugin-message")); class ErrorBoundary extends react_1.PureComponent { constructor() { super(...arguments); this.state = { hasError: false, }; } static getDerivedStateFromError(error) { // Update state so the next render will show the fallback UI. return { hasError: true }; } componentDidCatch(error, errorInfo) { this.props.logError(error, errorInfo); } render() { if (this.state.hasError) { return (react_1.default.createElement(components_1.Exception, { banner: "https://gw.alipayobjects.com/zos/rmsportal/RVRUAYdCGeYNBWoKiIwB.svg", title: "500", description: "\u62B1\u6B49\uFF0C\u670D\u52A1\u5668\u51FA\u9519\u4E86" })); } return this.props.children; } } const mapState = (state) => ({}); const mapActions = (dispatch) => ({ logError(error, errorInfo) { dispatch({ type: `${message.NAMESPACE}/error/fatal`, payload: { message: error && error.message, stack: error && error.stack, componentStack: errorInfo.componentStack, }, }); }, }); exports.default = dva_1.connect(mapState, mapActions)(ErrorBoundary); // as ComponentClass<IErrorBoundaryProps>; //# sourceMappingURL=index.js.map