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 "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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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"]);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue