From cc4a69826fd2e3a716b0be0a99d9f591360a6154 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Tue, 3 Oct 2023 21:29:07 +0800 Subject: [PATCH] BUG fix: createdTopic, request --- src/store/utils/checkTopicPublish.ts | 5 ++++- src/utils/request.ts | 6 ++++-- src/views/edit/components/Button.vue | 2 -- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/store/utils/checkTopicPublish.ts b/src/store/utils/checkTopicPublish.ts index 1e298fda..5f643926 100644 --- a/src/store/utils/checkTopicPublish.ts +++ b/src/store/utils/checkTopicPublish.ts @@ -12,7 +12,7 @@ const isEditUpdateTopicData = (data: any): data is EditUpdateTopicRequestData => export const checkTopicPublish = ( textCount: number, topicData: EditCreateTopicRequestData | EditUpdateTopicRequestData -) => { +): boolean => { // 检查 tid if (isEditUpdateTopicData(topicData)) { // 话题 id 为零,应该。。。。不存在吧( @@ -37,11 +37,13 @@ export const checkTopicPublish = ( } if (textCount > 100007) { message('Content max length is 100007!', '内容最大长度为100007!', 'warn') + return false } // 检查 tag if (!topicData.tags.length) { message('Please use at least one tag!', '请至少使用一个标签!', 'warn') + return false } // 检查分类 @@ -51,6 +53,7 @@ export const checkTopicPublish = ( '请至少选择一个分类!', 'warn' ) + return false } // 都通过则返回真 diff --git a/src/utils/request.ts b/src/utils/request.ts index bd651318..eab008e6 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -5,6 +5,8 @@ import { onRequestError } from '@/error/onRequestError' type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' +const successResponseArray = [200, 201, 202, 204, 205, 206] + export type FetchOptions = { method: HttpMethod credentials: 'include' @@ -28,8 +30,8 @@ const kunFetchRequest = async ( const response = await fetch(fullUrl, { ...options, headers }) - // 后端的一切正常响应都被设为 200 了 - if (response.status != 200) { + // 不为 20X 则报错 + if (!successResponseArray.includes(response.status)) { // 处理错误,token 过期 await onRequestError(response) throw new Error('KUNGalgame Fetch Error occurred, but no problem') diff --git a/src/views/edit/components/Button.vue b/src/views/edit/components/Button.vue index 189e59ca..6379944e 100644 --- a/src/views/edit/components/Button.vue +++ b/src/views/edit/components/Button.vue @@ -37,8 +37,6 @@ const handlePublish = async () => { messageStore.info('AlertInfo.edit.publishSuccess') // 清除数据,并不再保存数据,因为此时该话题已被发布 useKUNGalgameEditStore().resetTopicData() - } else { - message('Failed to create new topic', '发布话题失败', 'error') } } else { messageStore.info('AlertInfo.edit.publishCancel')