From 11a0c94c218fcd72ad4cf2e0dbea39fbac06c558 Mon Sep 17 00:00:00 2001 From: allence Date: Tue, 18 Apr 2023 11:34:23 +0800 Subject: [PATCH] feat(web): common error handler --- .../app/database/mods/AddRulesModal/index.tsx | 7 ++--- .../signin/mods/LoginByPhonePanel/index.tsx | 2 -- .../pages/home/mods/CreateAppModal/index.tsx | 12 +++----- web/src/pages/home/mods/List/index.tsx | 29 ++++++++++--------- web/src/utils/request.ts | 9 ++++++ 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/web/src/pages/app/database/mods/AddRulesModal/index.tsx b/web/src/pages/app/database/mods/AddRulesModal/index.tsx index 29f84735d8..2fc538075f 100644 --- a/web/src/pages/app/database/mods/AddRulesModal/index.tsx +++ b/web/src/pages/app/database/mods/AddRulesModal/index.tsx @@ -59,11 +59,10 @@ const AddRulesModal = (props: { } try { const res = await createRulesMutation.mutateAsync(data); - if (res.error) { - throw new Error(res?.error); + if (!res.error) { + props.onSuccessSubmit(res.data); + onClose(); } - props.onSuccessSubmit(res.data); - onClose(); } catch (errors) { setError(errors?.toString()); return; diff --git a/web/src/pages/auth/signin/mods/LoginByPhonePanel/index.tsx b/web/src/pages/auth/signin/mods/LoginByPhonePanel/index.tsx index 8075b710b3..9165e37d49 100644 --- a/web/src/pages/auth/signin/mods/LoginByPhonePanel/index.tsx +++ b/web/src/pages/auth/signin/mods/LoginByPhonePanel/index.tsx @@ -77,8 +77,6 @@ export default function LoginByPhonePanel({ if (res?.data === "success") { showSuccess(t("AuthPanel.SmsCodeSendSuccess")); - } else { - showError(res.error); } }; diff --git a/web/src/pages/home/mods/CreateAppModal/index.tsx b/web/src/pages/home/mods/CreateAppModal/index.tsx index 11d657d573..01d5cb4ba8 100644 --- a/web/src/pages/home/mods/CreateAppModal/index.tsx +++ b/web/src/pages/home/mods/CreateAppModal/index.tsx @@ -124,7 +124,7 @@ const CreateAppModal = (props: { const currentSubscription = currentBundle.subscriptionOptions[0]; - const { showSuccess, showError } = useGlobalStore(); + const { showSuccess } = useGlobalStore(); const totalPrice = subscriptionOption.specialPrice; @@ -168,8 +168,6 @@ const CreateAppModal = (props: { setTimeout(() => { queryClient.invalidateQueries(APP_LIST_QUERY_KEY); }, 2000); - } else { - showError(res.error); } }; @@ -257,11 +255,9 @@ const CreateAppModal = (props: { {(bundles || []).map((bundle: TBundle) => { return ( { - return vale.displayName === subscriptionOption.displayName; - }, - )} + durationIndex={bundle.subscriptionOptions.findIndex((vale) => { + return vale.displayName === subscriptionOption.displayName; + })} onChange={onChange} bundle={bundle} isActive={bundle.id === value} diff --git a/web/src/pages/home/mods/List/index.tsx b/web/src/pages/home/mods/List/index.tsx index 0e943fea79..a10a9ca876 100644 --- a/web/src/pages/home/mods/List/index.tsx +++ b/web/src/pages/home/mods/List/index.tsx @@ -172,21 +172,22 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) { - - { - event?.preventDefault(); - await updateAppMutation.mutateAsync({ - appid: item.appid, - name: item.name, - state: APP_PHASE_STATUS.Restarting, - }); + { + event?.preventDefault(); + const res = await updateAppMutation.mutateAsync({ + appid: item.appid, + name: item.name, + state: APP_PHASE_STATUS.Restarting, + }); + if (!res.error) { setShouldRefetch(true); - }} - > - {t("SettingPanel.Restart")} - + } + }} + > + {t("SettingPanel.Restart")} { const { data } = response; + if (data?.error) { + toast({ + title: data?.error, + position: "top", + status: "error", + duration: 1500, + }); + } + return data; }, (error) => {