[release-2.0] feat: api client requests support configuring the mute parameter to hide exception toast (#752)

This is an automated cherry-pick of #744

/assign ruibaby

```release-note
None
```
pull/753/head
Halo Dev Bot 2022-12-07 11:44:53 +08:00 committed by GitHub
parent 22685fc298
commit 18012cd33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 29 deletions

8
env.d.ts vendored
View File

@ -6,6 +6,8 @@ import type { CoreMenuGroupId } from "@halo-dev/console-shared";
import "vue-router"; import "vue-router";
import "axios";
declare module "*.vue" { declare module "*.vue" {
import type { DefineComponent } from "vue"; import type { DefineComponent } from "vue";
// eslint-disable-next-line // eslint-disable-next-line
@ -28,3 +30,9 @@ declare module "vue-router" {
}; };
} }
} }
declare module "axios" {
export interface AxiosRequestConfig {
mute?: boolean;
}
}

View File

@ -91,6 +91,9 @@ export function useSettingForm(
const response = await apiClient.extension.configMap.getv1alpha1ConfigMap( const response = await apiClient.extension.configMap.getv1alpha1ConfigMap(
{ {
name: configMapName.value, name: configMapName.value,
},
{
mute: true,
} }
); );

View File

@ -126,15 +126,25 @@ const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => {
const { settingName, configMapName } = theme.spec; const { settingName, configMapName } = theme.spec;
if (settingName) { if (settingName) {
await apiClient.extension.setting.deletev1alpha1Setting({ await apiClient.extension.setting.deletev1alpha1Setting(
name: settingName, {
}); name: settingName,
},
{
mute: true,
}
);
} }
if (configMapName) { if (configMapName) {
await apiClient.extension.configMap.deletev1alpha1ConfigMap({ await apiClient.extension.configMap.deletev1alpha1ConfigMap(
name: configMapName, {
}); name: configMapName,
},
{
mute: true,
}
);
} }
} catch (e) { } catch (e) {
console.error("Failed to uninstall theme", e); console.error("Failed to uninstall theme", e);

View File

@ -84,15 +84,25 @@ export function usePluginLifeCycle(
const { settingName, configMapName } = plugin.value.spec; const { settingName, configMapName } = plugin.value.spec;
if (settingName) { if (settingName) {
await apiClient.extension.setting.deletev1alpha1Setting({ await apiClient.extension.setting.deletev1alpha1Setting(
name: settingName, {
}); name: settingName,
},
{
mute: true,
}
);
} }
if (configMapName) { if (configMapName) {
await apiClient.extension.configMap.deletev1alpha1ConfigMap({ await apiClient.extension.configMap.deletev1alpha1ConfigMap(
name: configMapName, {
}); name: configMapName,
},
{
mute: true,
}
);
} }
} catch (e) { } catch (e) {
console.error("Failed to uninstall plugin", e); console.error("Failed to uninstall plugin", e);

View File

@ -1,6 +1,5 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import axios from "axios"; import { apiClient } from "@/utils/api-client";
import type { ConfigMap } from "@halo-dev/api-client";
interface SystemState { interface SystemState {
isSetup: boolean; isSetup: boolean;
@ -20,14 +19,13 @@ export const useSystemStatesStore = defineStore({
actions: { actions: {
async fetchSystemStates() { async fetchSystemStates() {
try { try {
const { data } = await axios.get<ConfigMap>( const { data } =
`${ await apiClient.extension.configMap.getv1alpha1ConfigMap(
import.meta.env.VITE_API_URL {
}/api/v1alpha1/configmaps/system-states`, name: "system-states",
{ },
withCredentials: true, { mute: true }
} );
);
if (data.data) { if (data.data) {
this.states = JSON.parse(data.data["states"]); this.states = JSON.parse(data.data["states"]);

View File

@ -14,21 +14,28 @@ export const useThemeStore = defineStore("theme", {
async fetchActivatedTheme() { async fetchActivatedTheme() {
try { try {
const { data } = const { data } =
await apiClient.extension.configMap.getv1alpha1ConfigMap({ await apiClient.extension.configMap.getv1alpha1ConfigMap(
name: "system", {
}); name: "system",
},
{ mute: true }
);
if (!data.data?.theme) { if (!data.data?.theme) {
// Todo: show error
return; return;
} }
const themeConfig = JSON.parse(data.data.theme); const themeConfig = JSON.parse(data.data.theme);
const { data: themeData } = const { data: themeData } =
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme({ await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme(
name: themeConfig.active, {
}); name: themeConfig.active,
},
{
mute: true,
}
);
this.activatedTheme = themeData; this.activatedTheme = themeData;
} catch (e) { } catch (e) {

View File

@ -73,6 +73,12 @@ axiosInstance.interceptors.response.use(
const { title } = errorResponse.data; const { title } = errorResponse.data;
// Don't show error toast
// see https://github.com/halo-dev/halo/issues/2836
if (errorResponse.config.mute) {
return Promise.reject(error);
}
if (status === 400) { if (status === 400) {
Toast.error(`请求参数错误:${title}`); Toast.error(`请求参数错误:${title}`);
} else if (status === 401) { } else if (status === 401) {