mirror of
https://github.com/certimate-go/certimate.git
synced 2026-06-30 21:05:12 +08:00
refactor: clean code
This commit is contained in:
parent
de6384205a
commit
ab67235369
@ -11,7 +11,7 @@ import { type AccessModel } from "@/domain/access";
|
||||
import { ACCESS_USAGES } from "@/domain/provider";
|
||||
import { useTriggerElement, useZustandShallowSelector } from "@/hooks";
|
||||
import { useAccessesStore } from "@/stores/access";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
import AccessForm, { type AccessFormModes, type AccessFormProps, type AccessFormUsages } from "./AccessForm";
|
||||
|
||||
@ -97,7 +97,7 @@ const AccessEditDrawer = ({ afterSubmit, mode, data, loading, trigger, usage, ..
|
||||
|
||||
afterSubmit?.(formValues);
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
} finally {
|
||||
@ -146,7 +146,7 @@ const AccessEditDrawer = ({ afterSubmit, mode, data, loading, trigger, usage, ..
|
||||
await testPushNotification({ provider: fieldProvider, accessId: data!.id });
|
||||
message.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
} finally {
|
||||
setIsTesting(false);
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import { listByWorkflowRunId as listCertificatesByWorkflowRunId } from "@/reposi
|
||||
import { listByWorkflowRunId as listLogsByWorkflowRunId } from "@/repository/workflowLog";
|
||||
import { subscribe as subscribeWorkflowRun } from "@/repository/workflowRun";
|
||||
import { mergeCls } from "@/utils/css";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
import WorkflowDesigner from "./designer/Designer";
|
||||
import WorkflowToolbar from "./designer/Toolbar";
|
||||
@ -439,7 +439,7 @@ const WorkflowRunArtifacts = ({ runId }: { runId: string }) => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
},
|
||||
|
||||
@ -23,7 +23,7 @@ import { type WorkflowNodeConfigForBizApply, defaultNodeConfigForBizApply } from
|
||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||
import { useAccessesStore } from "@/stores/access";
|
||||
import { useContactEmailsStore } from "@/stores/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
import { matchSearchOption } from "@/utils/search";
|
||||
import { isDomain, isHostname } from "@/utils/validator";
|
||||
|
||||
@ -232,7 +232,7 @@ const BizApplyNodeConfigForm = ({ node, ...props }: BizApplyNodeConfigFormProps)
|
||||
{
|
||||
name: "keyContent",
|
||||
value: value,
|
||||
errors: [getErrMsg(err)],
|
||||
errors: [unwrapErrMsg(err)],
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import Show from "@/components/Show";
|
||||
import Tips from "@/components/Tips";
|
||||
import { type WorkflowNodeConfigForBizUpload, defaultNodeConfigForBizUpload } from "@/domain/workflow";
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
import { isUrlWithHttpOrHttps } from "@/utils/validator";
|
||||
import { getSubjectAltNames as getX509SubjectAltNames } from "@/utils/x509";
|
||||
|
||||
@ -80,7 +80,7 @@ const BizUploadNodeConfigForm = ({ node, ...props }: BizUploadNodeConfigFormProp
|
||||
{
|
||||
name: "certificate",
|
||||
value: value,
|
||||
errors: [getErrMsg(err)],
|
||||
errors: [unwrapErrMsg(err)],
|
||||
},
|
||||
]);
|
||||
}
|
||||
@ -100,7 +100,7 @@ const BizUploadNodeConfigForm = ({ node, ...props }: BizUploadNodeConfigFormProp
|
||||
{
|
||||
name: "privateKey",
|
||||
value: value,
|
||||
errors: [getErrMsg(err)],
|
||||
errors: [unwrapErrMsg(err)],
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import { Anchor, type AnchorProps, App, Button, Drawer, Dropdown, Flex, type For
|
||||
import { isEqual } from "radash";
|
||||
|
||||
import Show from "@/components/Show";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
import { type NodeRegistry } from "../nodes/typings";
|
||||
|
||||
@ -60,7 +60,7 @@ export const NodeConfigDrawer = ({ children, afterClose, anchor, footer = true,
|
||||
node.form!.setValueIn("config", formValues);
|
||||
node.form!.validate();
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
} finally {
|
||||
|
||||
@ -17,7 +17,7 @@ import { ACCESS_USAGES, accessProvidersMap } from "@/domain/provider";
|
||||
import { useAppSettings, useZustandShallowSelector } from "@/hooks";
|
||||
import { get as getAccess } from "@/repository/access";
|
||||
import { useAccessesStore } from "@/stores/access";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
type AccessUsages = AccessEditDrawerProps["usage"];
|
||||
|
||||
@ -41,7 +41,7 @@ const AccessList = () => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
});
|
||||
});
|
||||
|
||||
@ -327,7 +327,7 @@ const AccessList = () => {
|
||||
refreshData();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -359,7 +359,7 @@ const AccessList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -429,7 +429,7 @@ const AccessList = () => {
|
||||
<Empty
|
||||
className="py-24"
|
||||
title={loadError ? t("common.text.nodata_failed") : t("access.nodata.title")}
|
||||
description={loadError ? getErrMsg(loadError) : t("access.nodata.description")}
|
||||
description={loadError ? unwrapErrMsg(loadError) : t("access.nodata.description")}
|
||||
icon={<IconFingerprint size={24} />}
|
||||
extra={
|
||||
loadError ? (
|
||||
|
||||
@ -10,7 +10,7 @@ import { type AccessModel } from "@/domain/access";
|
||||
import { ACCESS_USAGES } from "@/domain/provider";
|
||||
import { useZustandShallowSelector } from "@/hooks";
|
||||
import { useAccessesStore } from "@/stores/access";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const AccessNew = () => {
|
||||
const navigate = useNavigate();
|
||||
@ -51,7 +51,7 @@ const AccessNew = () => {
|
||||
|
||||
navigate(`/accesses?usage=${providerUsage}`, { replace: true });
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
} finally {
|
||||
|
||||
@ -15,7 +15,7 @@ import { CERTIFICATE_SOURCES, type CertificateModel } from "@/domain/certificate
|
||||
import { useAppSettings, useZustandShallowSelector } from "@/hooks";
|
||||
import { get as getCertificate, list as listCertificates, remove as removeCertificate } from "@/repository/certificate";
|
||||
import { usePersistenceSettingsStore } from "@/stores/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const CertificateList = () => {
|
||||
const navigate = useNavigate();
|
||||
@ -290,7 +290,7 @@ const CertificateList = () => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
},
|
||||
@ -343,7 +343,7 @@ const CertificateList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -371,7 +371,7 @@ const CertificateList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -403,7 +403,7 @@ const CertificateList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -463,7 +463,7 @@ const CertificateList = () => {
|
||||
<Empty
|
||||
className="py-24"
|
||||
title={loadError ? t("common.text.nodata_failed") : t("certificate.nodata.title")}
|
||||
description={loadError ? getErrMsg(loadError) : t("certificate.nodata.description")}
|
||||
description={loadError ? unwrapErrMsg(loadError) : t("certificate.nodata.description")}
|
||||
icon={<IconCertificate size={24} />}
|
||||
extra={
|
||||
loadError ? (
|
||||
|
||||
@ -30,7 +30,7 @@ import { type WorkflowRunModel } from "@/domain/workflowRun";
|
||||
import { useBrowserTheme, useVersionChecker } from "@/hooks";
|
||||
import { get as getWorkflowRun, list as listWorkflowRuns } from "@/repository/workflowRun";
|
||||
import { mergeCls } from "@/utils/css";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const Dashboard = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -149,7 +149,7 @@ const StatisticCards = ({ className, style }: { className?: string; style?: Reac
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
},
|
||||
@ -365,7 +365,7 @@ const WorkflowRunHistoryTable = ({ className, style }: { className?: string; sty
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
},
|
||||
@ -400,7 +400,7 @@ const WorkflowRunHistoryTable = ({ className, style }: { className?: string; sty
|
||||
<Empty
|
||||
className="py-24"
|
||||
title={loadError ? t("common.text.nodata_failed") : t("common.text.nodata")}
|
||||
description={loadError ? getErrMsg(loadError) : t("dashboard.latest_workflow_runs.nodata.description")}
|
||||
description={loadError ? unwrapErrMsg(loadError) : t("dashboard.latest_workflow_runs.nodata.description")}
|
||||
icon={<IconHistory size={24} />}
|
||||
extra={
|
||||
loadError ? (
|
||||
|
||||
@ -13,7 +13,7 @@ import AppVersion from "@/components/AppVersion";
|
||||
import { useAntdForm, useBrowserTheme } from "@/hooks";
|
||||
|
||||
import { authWithPassword } from "@/repository/admin";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const Login = () => {
|
||||
const navigage = useNavigate();
|
||||
@ -59,7 +59,7 @@ const Login = () => {
|
||||
await authWithPassword(values.username, values.password);
|
||||
await navigage("/");
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import DrawerForm from "@/components/DrawerForm";
|
||||
import Tips from "@/components/Tips";
|
||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||
import { useNotifyTemplatesStore } from "@/stores/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const MAX_TEMPLATE_COUNT = 99;
|
||||
|
||||
@ -35,7 +35,7 @@ const PresetListNotifyTemplates = () => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
});
|
||||
});
|
||||
|
||||
@ -77,7 +77,7 @@ const PresetListNotifyTemplates = () => {
|
||||
await removeTemplateByIndex(index);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -90,7 +90,7 @@ const PresetListNotifyTemplates = () => {
|
||||
setCreateDrawerOpen(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
@ -105,7 +105,7 @@ const PresetListNotifyTemplates = () => {
|
||||
setDetailDrawerOpen(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import DrawerForm from "@/components/DrawerForm";
|
||||
import Tips from "@/components/Tips";
|
||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||
import { useScriptTemplatesStore } from "@/stores/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const MAX_TEMPLATE_COUNT = 99;
|
||||
|
||||
@ -35,7 +35,7 @@ const PresetListScriptTemplates = () => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
});
|
||||
});
|
||||
|
||||
@ -77,7 +77,7 @@ const PresetListScriptTemplates = () => {
|
||||
await removeTemplateByIndex(index);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -90,7 +90,7 @@ const PresetListScriptTemplates = () => {
|
||||
setCreateDrawerOpen(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
@ -105,7 +105,7 @@ const PresetListScriptTemplates = () => {
|
||||
setDetailDrawerOpen(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import { z } from "zod";
|
||||
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { authWithPassword, getAuthStore, save as saveAdmin } from "@/repository/admin";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsAccount = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -60,7 +60,7 @@ const SettingsAccountUsername = ({ className, style }: { className?: string; sty
|
||||
navigate("/login");
|
||||
}, 500);
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
}
|
||||
@ -163,7 +163,7 @@ const SettingsAccountPassword = ({ className, style }: { className?: string; sty
|
||||
navigate("/login");
|
||||
}, 500);
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import Show from "@/components/Show";
|
||||
import { listCronJobs, listLogs } from "@/repository/system";
|
||||
import { getNextCronExecutions } from "@/utils/cron";
|
||||
import { mergeCls } from "@/utils/css";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsDiagnostics = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -139,7 +139,7 @@ const SettingsDiagnosticsLogs = ({ className, style }: { className?: string; sty
|
||||
<Show.Case when={listData.length === 0}>
|
||||
<div className="px-4 py-2">
|
||||
<div className="w-full overflow-hidden">
|
||||
<div className="text-xs leading-relaxed text-stone-400">{loadError ? `> ${getErrMsg(loadError)}` : "> no logs avaiable"}</div>
|
||||
<div className="text-xs leading-relaxed text-stone-400">{loadError ? `> ${unwrapErrMsg(loadError)}` : "> no logs avaiable"}</div>
|
||||
</div>
|
||||
<div className="flex w-full items-center">
|
||||
<a onClick={handleReloadClick}>
|
||||
@ -241,7 +241,7 @@ const SettingsDiagnosticsCrons = ({ className, style }: { className?: string; st
|
||||
loading={loading}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<Empty description={loadError ? getErrMsg(loadError) : t("common.text.nodata")} image={Empty.PRESENTED_IMAGE_SIMPLE}>
|
||||
<Empty description={loadError ? unwrapErrMsg(loadError) : t("common.text.nodata")} image={Empty.PRESENTED_IMAGE_SIMPLE}>
|
||||
{loadError && (
|
||||
<Button ghost icon={<IconReload size="1.25em" />} type="primary" onClick={handleReloadClick}>
|
||||
{t("common.button.reload")}
|
||||
|
||||
@ -10,7 +10,7 @@ import Show from "@/components/Show";
|
||||
import { type PersistenceSettingsContent } from "@/domain/settings";
|
||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||
import { usePersistenceSettingsStore } from "@/stores/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsPersistence = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -28,7 +28,7 @@ const SettingsPersistence = () => {
|
||||
|
||||
message.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import { type SSLProviderSettingsContent } from "@/domain/settings";
|
||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||
import { useSSLProviderSettingsStore } from "@/stores/settings";
|
||||
import { mergeCls } from "@/utils/css";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const SettingsSSLProvider = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -86,7 +86,7 @@ const SettingsSSLProvider = () => {
|
||||
|
||||
message.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
} finally {
|
||||
setFormPending(false);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import { WORKFLOW_RUN_STATUSES } from "@/domain/workflowRun";
|
||||
import { useZustandShallowSelector } from "@/hooks";
|
||||
import { useWorkflowStore } from "@/stores/workflow";
|
||||
import { mergeCls } from "@/utils/css";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const WorkflowDetail = () => {
|
||||
const location = useLocation();
|
||||
@ -26,7 +26,7 @@ const WorkflowDetail = () => {
|
||||
useEffect(() => {
|
||||
Promise.try(() => workflowState.init(workflowId!)).catch((err) => {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
});
|
||||
|
||||
return () => {
|
||||
@ -102,7 +102,7 @@ const WorkflowDetail = () => {
|
||||
await workflowState.setEnabled(!workflow.enabled);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
@ -205,7 +205,7 @@ const WorkflowDetailBaseName = () => {
|
||||
try {
|
||||
await workflowStore.setName(value);
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
}
|
||||
@ -283,7 +283,7 @@ const WorkflowDetailBaseDescription = () => {
|
||||
try {
|
||||
await workflowStore.setDescription(value);
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import WorkflowGraphExportModal from "@/components/workflow/WorkflowGraphExportM
|
||||
import WorkflowGraphImportModal from "@/components/workflow/WorkflowGraphImportModal";
|
||||
import { useAppSettings, useZustandShallowSelector } from "@/hooks";
|
||||
import { useWorkflowStore } from "@/stores/workflow";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const WorkflowDetailDesign = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -55,7 +55,7 @@ const WorkflowDetailDesign = () => {
|
||||
await workflowStore.orchestrate(graph);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
} finally {
|
||||
designerPending.current = false;
|
||||
}
|
||||
@ -72,7 +72,7 @@ const WorkflowDetailDesign = () => {
|
||||
message.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -94,7 +94,7 @@ const WorkflowDetailDesign = () => {
|
||||
message.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -116,7 +116,7 @@ const WorkflowDetailDesign = () => {
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
message.destroy(loadingKey);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -214,7 +214,7 @@ const WorkflowDetailDesign = () => {
|
||||
|
||||
{!!designerError && (
|
||||
<div className="absolute top-1/2 left-1/2 z-10 w-full -translate-1/2 px-4">
|
||||
<Result status="warning" title="Data corruption!" subTitle={`Error: ${getErrMsg(designerError)}`} />
|
||||
<Result status="warning" title="Data corruption!" subTitle={`Error: ${unwrapErrMsg(designerError)}`} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import { WORKFLOW_RUN_STATUSES, type WorkflowRunModel } from "@/domain/workflowR
|
||||
import { useAppSettings, useZustandShallowSelector } from "@/hooks";
|
||||
import { get as getWorkflowRun, list as listWorkflowRuns, remove as removeWorkflowRun, subscribe as subscribeWorkflowRun } from "@/repository/workflowRun";
|
||||
import { useWorkflowStore } from "@/stores/workflow";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const WorkflowDetailRuns = () => {
|
||||
const { t } = useTranslation();
|
||||
@ -211,7 +211,7 @@ const WorkflowDetailRuns = () => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
},
|
||||
@ -274,7 +274,7 @@ const WorkflowDetailRuns = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -300,7 +300,7 @@ const WorkflowDetailRuns = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -334,7 +334,7 @@ const WorkflowDetailRuns = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -358,7 +358,7 @@ const WorkflowDetailRuns = () => {
|
||||
<Empty
|
||||
className="py-24"
|
||||
title={loadError ? t("common.text.nodata_failed") : t("workflow_run.nodata.title")}
|
||||
description={loadError ? getErrMsg(loadError) : t("workflow_run.nodata.description")}
|
||||
description={loadError ? unwrapErrMsg(loadError) : t("workflow_run.nodata.description")}
|
||||
icon={<IconHistory size={24} />}
|
||||
/>
|
||||
),
|
||||
|
||||
@ -14,7 +14,7 @@ import WorkflowStatus from "@/components/workflow/WorkflowStatus";
|
||||
import { WORKFLOW_TRIGGERS, type WorkflowModel, duplicateNodes } from "@/domain/workflow";
|
||||
import { useAppSettings } from "@/hooks";
|
||||
import { get as getWorkflow, list as listWorkflows, remove as removeWorkflow, save as saveWorkflow } from "@/repository/workflow";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const WorkflowList = () => {
|
||||
const navigate = useNavigate();
|
||||
@ -280,7 +280,7 @@ const WorkflowList = () => {
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
},
|
||||
@ -335,7 +335,7 @@ const WorkflowList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
@ -346,7 +346,7 @@ const WorkflowList = () => {
|
||||
message.info(t("workflow.action.execute.prompt"));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
};
|
||||
|
||||
@ -371,7 +371,7 @@ const WorkflowList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -397,7 +397,7 @@ const WorkflowList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -429,7 +429,7 @@ const WorkflowList = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -493,7 +493,7 @@ const WorkflowList = () => {
|
||||
<Empty
|
||||
className="py-24"
|
||||
title={loadError ? t("common.text.nodata_failed") : t("workflow.nodata.title")}
|
||||
description={loadError ? getErrMsg(loadError) : t("workflow.nodata.description")}
|
||||
description={loadError ? unwrapErrMsg(loadError) : t("workflow.nodata.description")}
|
||||
icon={<IconHierarchy3 size={24} />}
|
||||
extra={
|
||||
loadError ? (
|
||||
|
||||
@ -15,7 +15,7 @@ import {
|
||||
newNode,
|
||||
} from "@/domain/workflow";
|
||||
import { save as saveWorkflow } from "@/repository/workflow";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { unwrapErrMsg } from "@/utils/error";
|
||||
|
||||
const TEMPLATE_KEY_BLANK = "blank" as const;
|
||||
const TEMPLATE_KEY_STANDARD = "standard" as const;
|
||||
@ -242,7 +242,7 @@ const WorkflowNew = () => {
|
||||
workflow = await saveWorkflow(workflow);
|
||||
navigate(`/workflows/${workflow.id}`, { replace: true });
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
} finally {
|
||||
@ -266,7 +266,7 @@ const WorkflowNew = () => {
|
||||
workflow = await saveWorkflow(workflow);
|
||||
navigate(`/workflows/${workflow.id}`, { replace: true });
|
||||
} catch (err) {
|
||||
notification.error({ title: t("common.text.request_error"), description: getErrMsg(err) });
|
||||
notification.error({ title: t("common.text.request_error"), description: unwrapErrMsg(err) });
|
||||
|
||||
throw err;
|
||||
} finally {
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
|
||||
export const getErrMsg = (error: unknown): string => {
|
||||
export const unwrapErrMsg = (error: unknown): string => {
|
||||
if (error instanceof ClientResponseError) {
|
||||
return Object.keys(error.response ?? {}).length ? getErrMsg(error.response) : error.message;
|
||||
return Object.keys(error.response ?? {}).length ? unwrapErrMsg(error.response) : error.message;
|
||||
} else if (error instanceof Error) {
|
||||
return error.message;
|
||||
} else if (typeof error === "object" && error != null) {
|
||||
if ("message" in error) {
|
||||
return getErrMsg(error.message);
|
||||
return unwrapErrMsg(error.message);
|
||||
} else if ("msg" in error) {
|
||||
return getErrMsg(error.msg);
|
||||
return unwrapErrMsg(error.msg);
|
||||
}
|
||||
} else if (typeof error === "string") {
|
||||
return error || "Unknown error";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user