mirror of https://github.com/halo-dev/halo
feat: add retry mechanism for publishing posts in user center (#6406)
#### What type of PR is this? /area ui /kind improvement /milestone 2.18.x #### What this PR does / why we need it: 为个人中心发布文章的操作添加重试机制,方式后端因为乐观锁出现异常错误。 #### Which issue(s) this PR fixes: Fixes #6349 #### Does this PR introduce a user-facing change? ```release-note 为个人中心发布文章的操作添加重试机制,方式后端因为乐观锁出现异常错误。 ```pull/6411/head
parent
429b832ba8
commit
f7ee732c62
|
@ -29,7 +29,7 @@ import { useMutation } from "@tanstack/vue-query";
|
||||||
import { usePostUpdateMutate } from "@uc/modules/contents/posts/composables/use-post-update-mutate";
|
import { usePostUpdateMutate } from "@uc/modules/contents/posts/composables/use-post-update-mutate";
|
||||||
import { useLocalStorage } from "@vueuse/core";
|
import { useLocalStorage } from "@vueuse/core";
|
||||||
import { useRouteQuery } from "@vueuse/router";
|
import { useRouteQuery } from "@vueuse/router";
|
||||||
import type { AxiosRequestConfig } from "axios";
|
import { AxiosError, type AxiosRequestConfig } from "axios";
|
||||||
import type { ComputedRef } from "vue";
|
import type { ComputedRef } from "vue";
|
||||||
import { computed, nextTick, onMounted, provide, ref, toRef, watch } from "vue";
|
import { computed, nextTick, onMounted, provide, ref, toRef, watch } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
@ -386,10 +386,16 @@ const { mutateAsync: handlePublish, isLoading: isPublishing } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await handleSave({ mute: true });
|
await handleSave({ mute: true });
|
||||||
|
|
||||||
return await ucApiClient.content.post.publishMyPost({
|
return await ucApiClient.content.post.publishMyPost(
|
||||||
|
{
|
||||||
name: formState.value.metadata.name,
|
name: formState.value.metadata.name,
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
mute: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
retry: 3,
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
Toast.success(t("core.common.toast.publish_success"), {
|
Toast.success(t("core.common.toast.publish_success"), {
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
|
@ -397,8 +403,13 @@ const { mutateAsync: handlePublish, isLoading: isPublishing } = useMutation({
|
||||||
handleClearCache(formState.value.metadata.name);
|
handleClearCache(formState.value.metadata.name);
|
||||||
router.push({ name: "Posts" });
|
router.push({ name: "Posts" });
|
||||||
},
|
},
|
||||||
onError() {
|
onError(error: Error) {
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
const { detail, title } = error.response?.data || {};
|
||||||
|
Toast.error(detail || title);
|
||||||
|
} else {
|
||||||
Toast.error(t("core.common.toast.publish_failed_and_retry"));
|
Toast.error(t("core.common.toast.publish_failed_and_retry"));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue