Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): common error handler #1040

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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