oak-frontend-base/lib/platforms/web/initialize/AppError.js

70 lines
4.3 KiB
JavaScript

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const antd_1 = require("antd");
const Exception_1 = require("oak-domain/lib/types/Exception");
const ErrorPage_1 = require("../../../types/ErrorPage");
const ErrorPage = (0, react_1.lazy)(() => Promise.resolve().then(() => __importStar(require('../../../components/errorPage'))));
function Error(props) {
const { error, features } = props;
if (error instanceof Exception_1.OakException) {
if (error instanceof Exception_1.OakNetworkException) {
// 网络中断出现的异常
return ((0, jsx_runtime_1.jsxs)(ErrorPage, { code: ErrorPage_1.ECode.error, title: "\u7F51\u7EDC\u5F02\u5E38", desc: "\u62B1\u6B49\uFF0C\u7F51\u7EDC\u8BBF\u95EE\u5931\u8D25\uFF01", children: [(0, jsx_runtime_1.jsx)(ErrorMessage, { error: error }), (0, jsx_runtime_1.jsx)(antd_1.Button, { type: "primary", onClick: async () => {
window.location.reload();
}, children: "\u68C0\u67E5\u7F51\u7EDC" })] }));
}
if (error instanceof Exception_1.OakServerProxyException) {
// 服务器代理异常
return ((0, jsx_runtime_1.jsxs)(ErrorPage, { code: ErrorPage_1.ECode.error, title: "\u670D\u52A1\u5668\u4EE3\u7406\u5F02\u5E38", desc: "\u62B1\u6B49\uFF0C\u670D\u52A1\u5668\u4EE3\u7406\u51FA\u73B0\u9519\u8BEF\uFF01", children: [(0, jsx_runtime_1.jsx)(ErrorMessage, { error: error }), (0, jsx_runtime_1.jsx)(antd_1.Button, { type: "primary", onClick: async () => {
window.location.reload();
}, children: "\u68C0\u67E5\u670D\u52A1\u5668\u4EE3\u7406" })] }));
}
return ((0, jsx_runtime_1.jsxs)(ErrorPage, { code: ErrorPage_1.ECode.error, title: "\u7CFB\u7EDF\u5185\u90E8\u9519\u8BEF", desc: "\u62B1\u6B49\uFF0C\u7CFB\u7EDF\u5185\u90E8\u9519\u8BEF\uFF0C\u6211\u4EEC\u7684\u6280\u672F\u4EBA\u5458\u6B63\u5728\u5FEB\u9A6C\u52A0\u97AD\u7684\u4FEE\u590D", children: [(0, jsx_runtime_1.jsx)(ErrorMessage, { error: error }), (0, jsx_runtime_1.jsx)(antd_1.Button, { type: "primary", onClick: async () => {
window.location.reload();
}, children: "\u8054\u7CFB\u6211\u4EEC" })] }));
}
return ((0, jsx_runtime_1.jsxs)(ErrorPage, { code: ErrorPage_1.ECode.error, title: "\u6570\u636E\u7F13\u5B58\u5931\u6548", desc: "\u62B1\u6B49\uFF0C\u6570\u636E\u7F13\u5B58\u5931\u6548\uFF0C\u9700\u8981\u6E05\u9664\u7F13\u5B58\uFF0C\u8BF7\u70B9\u51FB\u3010\u6E05\u9664\u7F13\u5B58\u3011", children: [(0, jsx_runtime_1.jsx)(ErrorMessage, { error: error }), (0, jsx_runtime_1.jsx)(antd_1.Button, { type: "primary", onClick: async () => {
await features.localStorage.clear();
window.location.reload();
}, children: "\u6E05\u9664\u7F13\u5B58" })] }));
}
function ErrorMessage(props) {
const { error } = props;
if (process.env.NODE_ENV === 'development') {
return ((0, jsx_runtime_1.jsx)("span", { style: {
marginBottom: 24,
color: 'red',
fontSize: 14,
marginLeft: 24,
marginRight: 24,
}, children: typeof error === 'object' ? error.message : error }));
}
return null;
}
exports.default = Error;