BUG fix: createdTopic, request

This commit is contained in:
KUN1007 2023-10-03 21:29:07 +08:00
parent 6269037d5b
commit cc4a69826f
3 changed files with 8 additions and 5 deletions

View file

@ -12,7 +12,7 @@ const isEditUpdateTopicData = (data: any): data is EditUpdateTopicRequestData =>
export const checkTopicPublish = ( export const checkTopicPublish = (
textCount: number, textCount: number,
topicData: EditCreateTopicRequestData | EditUpdateTopicRequestData topicData: EditCreateTopicRequestData | EditUpdateTopicRequestData
) => { ): boolean => {
// 检查 tid // 检查 tid
if (isEditUpdateTopicData(topicData)) { if (isEditUpdateTopicData(topicData)) {
// 话题 id 为零,应该。。。。不存在吧( // 话题 id 为零,应该。。。。不存在吧(
@ -37,11 +37,13 @@ export const checkTopicPublish = (
} }
if (textCount > 100007) { if (textCount > 100007) {
message('Content max length is 100007!', '内容最大长度为100007', 'warn') message('Content max length is 100007!', '内容最大长度为100007', 'warn')
return false
} }
// 检查 tag // 检查 tag
if (!topicData.tags.length) { if (!topicData.tags.length) {
message('Please use at least one tag!', '请至少使用一个标签!', 'warn') message('Please use at least one tag!', '请至少使用一个标签!', 'warn')
return false
} }
// 检查分类 // 检查分类
@ -51,6 +53,7 @@ export const checkTopicPublish = (
'请至少选择一个分类!', '请至少选择一个分类!',
'warn' 'warn'
) )
return false
} }
// 都通过则返回真 // 都通过则返回真

View file

@ -5,6 +5,8 @@ import { onRequestError } from '@/error/onRequestError'
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
const successResponseArray = [200, 201, 202, 204, 205, 206]
export type FetchOptions = { export type FetchOptions = {
method: HttpMethod method: HttpMethod
credentials: 'include' credentials: 'include'
@ -28,8 +30,8 @@ const kunFetchRequest = async <T>(
const response = await fetch(fullUrl, { ...options, headers }) const response = await fetch(fullUrl, { ...options, headers })
// 后端的一切正常响应都被设为 200 了 // 不为 20X 则报错
if (response.status != 200) { if (!successResponseArray.includes(response.status)) {
// 处理错误token 过期 // 处理错误token 过期
await onRequestError(response) await onRequestError(response)
throw new Error('KUNGalgame Fetch Error occurred, but no problem') throw new Error('KUNGalgame Fetch Error occurred, but no problem')

View file

@ -37,8 +37,6 @@ const handlePublish = async () => {
messageStore.info('AlertInfo.edit.publishSuccess') messageStore.info('AlertInfo.edit.publishSuccess')
// //
useKUNGalgameEditStore().resetTopicData() useKUNGalgameEditStore().resetTopicData()
} else {
message('Failed to create new topic', '发布话题失败', 'error')
} }
} else { } else {
messageStore.info('AlertInfo.edit.publishCancel') messageStore.info('AlertInfo.edit.publishCancel')