Browse Source

[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 2 years ago committed by GitHub
parent
commit
18012cd33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      env.d.ts
  2. 3
      src/composables/use-setting-form.ts
  3. 22
      src/modules/interface/themes/components/ThemeListModal.vue
  4. 22
      src/modules/system/plugins/composables/use-plugin.ts
  5. 18
      src/stores/system-states.ts
  6. 21
      src/stores/theme.ts
  7. 6
      src/utils/api-client.ts

8
env.d.ts vendored

@ -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;
}
}

3
src/composables/use-setting-form.ts

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

22
src/modules/interface/themes/components/ThemeListModal.vue

@ -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);

22
src/modules/system/plugins/composables/use-plugin.ts

@ -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);

18
src/stores/system-states.ts

@ -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"]);

21
src/stores/theme.ts

@ -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) {

6
src/utils/api-client.ts

@ -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…
Cancel
Save