@skbkontur/db-viewer-ui
Version:
Database Viewer with custom configuration
40 lines • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorHandlingContainer = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ErrorHandlingContainerModal_1 = require("./ErrorHandlingContainerModal");
const ErrorHandlingContainer = () => {
const [{ error, isFatal, showModal, stack }, setState] = (0, react_1.useState)({
isFatal: false,
error: null,
stack: null,
showModal: false,
});
const oldOnunhandledrejection = (0, react_1.useRef)(null);
(0, react_1.useEffect)(() => {
oldOnunhandledrejection.current = window.onunhandledrejection;
window.onunhandledrejection = (e, ...restArgs) => {
if (oldOnunhandledrejection.current) {
oldOnunhandledrejection.current(e, ...restArgs);
}
if (typeof e.preventDefault === "function") {
e.preventDefault();
}
setState({
showModal: true,
isFatal: false,
error: e.reason,
stack: e.reason.stack,
});
};
return () => {
window.onunhandledrejection = oldOnunhandledrejection.current;
};
}, []);
const handleHideModal = () => setState(s => (Object.assign(Object.assign({}, s), { showModal: false })));
const { message, serverErrorType, serverStackTrace } = (error || {});
return ((0, jsx_runtime_1.jsx)("div", { children: showModal && ((0, jsx_runtime_1.jsx)(ErrorHandlingContainerModal_1.ErrorHandlingContainerModal, { canClose: !isFatal, onClose: handleHideModal, message: serverErrorType + ": " + message, stack: stack, serverStack: serverStackTrace })) }));
};
exports.ErrorHandlingContainer = ErrorHandlingContainer;
//# sourceMappingURL=ErrorHandlingContainer.js.map