mirror of https://github.com/halo-dev/halo-admin
feat: api client requests support configuring the mute parameter to hide exception toast (#744)
#### What type of PR is this? /kind improvement /milestone 2.0.1 #### What this PR does / why we need it: 使用 api-client 进行网络请求时,支持添加 `mute` 参数以隐藏异常提示。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2836 #### Special notes for your reviewer: None #### Does this PR introduce a user-facing change? ```release-note None ```pull/747/head
parent
08d0835634
commit
812b8eda0d
|
@ -6,6 +6,8 @@ import type { CoreMenuGroupId } from "@halo-dev/console-shared";
|
|||
|
||||
import "vue-router";
|
||||
|
||||
import "axios";
|
||||
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
// eslint-disable-next-line
|
||||
|
@ -28,3 +30,9 @@ declare module "vue-router" {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare module "axios" {
|
||||
export interface AxiosRequestConfig {
|
||||
mute?: boolean;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ export function useSettingForm(
|
|||
const response = await apiClient.extension.configMap.getv1alpha1ConfigMap(
|
||||
{
|
||||
name: configMapName.value,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -126,15 +126,25 @@ const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => {
|
|||
const { settingName, configMapName } = theme.spec;
|
||||
|
||||
if (settingName) {
|
||||
await apiClient.extension.setting.deletev1alpha1Setting({
|
||||
name: settingName,
|
||||
});
|
||||
await apiClient.extension.setting.deletev1alpha1Setting(
|
||||
{
|
||||
name: settingName,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (configMapName) {
|
||||
await apiClient.extension.configMap.deletev1alpha1ConfigMap({
|
||||
name: configMapName,
|
||||
});
|
||||
await apiClient.extension.configMap.deletev1alpha1ConfigMap(
|
||||
{
|
||||
name: configMapName,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to uninstall theme", e);
|
||||
|
|
|
@ -84,15 +84,25 @@ export function usePluginLifeCycle(
|
|||
const { settingName, configMapName } = plugin.value.spec;
|
||||
|
||||
if (settingName) {
|
||||
await apiClient.extension.setting.deletev1alpha1Setting({
|
||||
name: settingName,
|
||||
});
|
||||
await apiClient.extension.setting.deletev1alpha1Setting(
|
||||
{
|
||||
name: settingName,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (configMapName) {
|
||||
await apiClient.extension.configMap.deletev1alpha1ConfigMap({
|
||||
name: configMapName,
|
||||
});
|
||||
await apiClient.extension.configMap.deletev1alpha1ConfigMap(
|
||||
{
|
||||
name: configMapName,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to uninstall plugin", e);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { defineStore } from "pinia";
|
||||
import axios from "axios";
|
||||
import type { ConfigMap } from "@halo-dev/api-client";
|
||||
import { apiClient } from "@/utils/api-client";
|
||||
|
||||
interface SystemState {
|
||||
isSetup: boolean;
|
||||
|
@ -20,14 +19,13 @@ export const useSystemStatesStore = defineStore({
|
|||
actions: {
|
||||
async fetchSystemStates() {
|
||||
try {
|
||||
const { data } = await axios.get<ConfigMap>(
|
||||
`${
|
||||
import.meta.env.VITE_API_URL
|
||||
}/api/v1alpha1/configmaps/system-states`,
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
);
|
||||
const { data } =
|
||||
await apiClient.extension.configMap.getv1alpha1ConfigMap(
|
||||
{
|
||||
name: "system-states",
|
||||
},
|
||||
{ mute: true }
|
||||
);
|
||||
|
||||
if (data.data) {
|
||||
this.states = JSON.parse(data.data["states"]);
|
||||
|
|
|
@ -14,21 +14,28 @@ export const useThemeStore = defineStore("theme", {
|
|||
async fetchActivatedTheme() {
|
||||
try {
|
||||
const { data } =
|
||||
await apiClient.extension.configMap.getv1alpha1ConfigMap({
|
||||
name: "system",
|
||||
});
|
||||
await apiClient.extension.configMap.getv1alpha1ConfigMap(
|
||||
{
|
||||
name: "system",
|
||||
},
|
||||
{ mute: true }
|
||||
);
|
||||
|
||||
if (!data.data?.theme) {
|
||||
// Todo: show error
|
||||
return;
|
||||
}
|
||||
|
||||
const themeConfig = JSON.parse(data.data.theme);
|
||||
|
||||
const { data: themeData } =
|
||||
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme({
|
||||
name: themeConfig.active,
|
||||
});
|
||||
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme(
|
||||
{
|
||||
name: themeConfig.active,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
|
||||
this.activatedTheme = themeData;
|
||||
} catch (e) {
|
||||
|
|
|
@ -73,6 +73,12 @@ axiosInstance.interceptors.response.use(
|
|||
|
||||
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) {
|
||||
Toast.error(`请求参数错误:${title}`);
|
||||
} else if (status === 401) {
|
||||
|
|
Loading…
Reference in New Issue