amis-rpc-design/node_modules/antd/es/alert/ErrorBoundary.js
2023-10-07 19:42:30 +08:00

64 lines
1.8 KiB
JavaScript

"use client";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import * as React from 'react';
import Alert from './Alert';
let ErrorBoundary = /*#__PURE__*/function (_React$Component) {
_inherits(ErrorBoundary, _React$Component);
var _super = _createSuper(ErrorBoundary);
function ErrorBoundary() {
var _this;
_classCallCheck(this, ErrorBoundary);
_this = _super.apply(this, arguments);
_this.state = {
error: undefined,
info: {
componentStack: ''
}
};
return _this;
}
_createClass(ErrorBoundary, [{
key: "componentDidCatch",
value: function componentDidCatch(error, info) {
this.setState({
error,
info
});
}
}, {
key: "render",
value: function render() {
const {
message,
description,
children
} = this.props;
const {
error,
info
} = this.state;
const componentStack = info && info.componentStack ? info.componentStack : null;
const errorMessage = typeof message === 'undefined' ? (error || '').toString() : message;
const errorDescription = typeof description === 'undefined' ? componentStack : description;
if (error) {
return /*#__PURE__*/React.createElement(Alert, {
type: "error",
message: errorMessage,
description: /*#__PURE__*/React.createElement("pre", {
style: {
fontSize: '0.9em',
overflowX: 'auto'
}
}, errorDescription)
});
}
return children;
}
}]);
return ErrorBoundary;
}(React.Component);
export default ErrorBoundary;