Skip to content

Commit

Permalink
feat(web): common error handler (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeezQ authored Apr 18, 2023
1 parent 0e7d812 commit a099568
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
7 changes: 3 additions & 4 deletions web/src/pages/app/database/mods/AddRulesModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions web/src/pages/auth/signin/mods/LoginByPhonePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export default function LoginByPhonePanel({

if (res?.data === "success") {
showSuccess(t("AuthPanel.SmsCodeSendSuccess"));
} else {
showError(res.error);
}
};

Expand Down
12 changes: 4 additions & 8 deletions web/src/pages/home/mods/CreateAppModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const CreateAppModal = (props: {

const currentSubscription = currentBundle.subscriptionOptions[0];

const { showSuccess, showError } = useGlobalStore();
const { showSuccess } = useGlobalStore();

const totalPrice = subscriptionOption.specialPrice;

Expand Down Expand Up @@ -168,8 +168,6 @@ const CreateAppModal = (props: {
setTimeout(() => {
queryClient.invalidateQueries(APP_LIST_QUERY_KEY);
}, 2000);
} else {
showError(res.error);
}
};

Expand Down Expand Up @@ -257,11 +255,9 @@ const CreateAppModal = (props: {
{(bundles || []).map((bundle: TBundle) => {
return (
<BundleItem
durationIndex={bundle.subscriptionOptions.findIndex(
(vale, index) => {
return vale.displayName === subscriptionOption.displayName;
},
)}
durationIndex={bundle.subscriptionOptions.findIndex((vale) => {
return vale.displayName === subscriptionOption.displayName;
})}
onChange={onChange}
bundle={bundle}
isActive={bundle.id === value}
Expand Down
29 changes: 15 additions & 14 deletions web/src/pages/home/mods/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,22 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
</MenuItem>
</CreateAppModal>

<MenuItem minH="40px" display={"block"}>
<span
className="text-primary block"
onClick={async (event) => {
event?.preventDefault();
await updateAppMutation.mutateAsync({
appid: item.appid,
name: item.name,
state: APP_PHASE_STATUS.Restarting,
});
<MenuItem
minH="40px"
display={"block"}
onClick={async (event) => {
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")}
</span>
}
}}
>
<span className="text-primary block">{t("SettingPanel.Restart")}</span>
</MenuItem>

<MenuItem
Expand Down
9 changes: 9 additions & 0 deletions web/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ request.interceptors.request.use(
request.interceptors.response.use(
(response: AxiosResponse) => {
const { data } = response;
if (data?.error) {
toast({
title: data?.error,
position: "top",
status: "error",
duration: 1500,
});
}

return data;
},
(error) => {
Expand Down

0 comments on commit a099568

Please sign in to comment.