From 8e3228d46130ea9fcd8ee1c23fcdca62fd8592be Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 11 Sep 2024 16:19:14 +0800 Subject: [PATCH] feat: Catch errors in getting mindmap #2247 (#2368) ### What problem does this PR solve? feat: Catch errors in getting mindmap #2247 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/hooks/chat-hooks.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/src/hooks/chat-hooks.ts b/web/src/hooks/chat-hooks.ts index 1d4205c37..bdd5b167e 100644 --- a/web/src/hooks/chat-hooks.ts +++ b/web/src/hooks/chat-hooks.ts @@ -16,7 +16,7 @@ import { buildMessageListWithUuid, isConversationIdExist } from '@/utils/chat'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { message } from 'antd'; import dayjs, { Dayjs } from 'dayjs'; -import { set } from 'lodash'; +import { has, set } from 'lodash'; import { useCallback, useMemo, useState } from 'react'; import { useSearchParams } from 'umi'; @@ -492,9 +492,16 @@ export const useFetchMindMap = () => { mutationKey: ['fetchMindMap'], gcTime: 0, mutationFn: async (params: IAskRequestBody) => { - const { data } = await chatService.getMindMap(params); + try { + const ret = await chatService.getMindMap(params); + return ret?.data?.data ?? []; + } catch (error) { + if (has(error, 'message')) { + message.error(error.message); + } - return data?.data ?? []; + return []; + } }, });