diff --git a/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue b/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue index 4144421b..a598c160 100644 --- a/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue +++ b/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue @@ -6,6 +6,7 @@ import type { BubbleProps } from 'vue-element-plus-x/types/Bubble'; import type { BubbleListInstance } from 'vue-element-plus-x/types/BubbleList'; import type { FilesCardProps } from 'vue-element-plus-x/types/FilesCard'; import type { ThinkingStatus } from 'vue-element-plus-x/types/Thinking'; +import { ElMessage } from 'element-plus'; import { useHookFetch } from 'hook-fetch/vue'; import { useRoute } from 'vue-router'; import { send } from '@/api'; @@ -148,7 +149,9 @@ function handleDataChunk(chunk: AnyObject) { // 封装错误处理逻辑 function handleError(err: any) { - console.log('Fetch error:-------', err); + if (err.status === 403) { + ElMessage.error('业务错误,请稍后再试'); + } console.error('Fetch error:', err); } diff --git a/Yi.Ai.Vue3/src/utils/request.ts b/Yi.Ai.Vue3/src/utils/request.ts index cf34ca90..f0900e61 100644 --- a/Yi.Ai.Vue3/src/utils/request.ts +++ b/Yi.Ai.Vue3/src/utils/request.ts @@ -1,4 +1,4 @@ -import type { HookFetchPlugin } from 'hook-fetch'; +import type { RequestConfig } from 'hook-fetch'; import FingerprintJS from '@fingerprintjs/fingerprintjs'; // 新增指纹库 import { ElMessage } from 'element-plus'; import hookFetch from 'hook-fetch'; @@ -70,7 +70,13 @@ export const request = hookFetch.create({ }); // JWT插件(保持原有逻辑) -function jwtPlugin(): HookFetchPlugin { +function jwtPlugin(): { + onError: (error: any) => Promise; + name: string; + beforeRequest: (config: any) => Promise>; + afterResponse: (response: any) => Promise; + beforeStream: (body: any, config: any) => Promise; +} { const userStore = useUserStore(); return { name: 'jwt', @@ -86,13 +92,10 @@ function jwtPlugin(): HookFetchPlugin { return config; }, + // 响应后处理 afterResponse: async (response: any) => { - console.log('response---', response); - console.log('response.headers---', response.headers); - console.log('response.response.headers---', response.response.headers); - if (response.response.headers?.refresh_token) { - console.log('返回有token---response.response.headers-:', response.response.headers); - userStore.setToken(response.response.headers?.access_token, response.response.headers?.refresh_token); + if (response.response.headers.get('access_token')) { + userStore.setToken(response.response.headers.get('access_token'), response.response.headers.get('refresh_token')); } if (response.result?.code === 200) @@ -112,9 +115,8 @@ function jwtPlugin(): HookFetchPlugin { ElMessage.error(response.result?.msg); return Promise.reject(response); }, + onError: async (error) => { - console.log('error---', error); - console.log('response---', error.response); if (error.status === 403) { // 弹窗提示 ElMessage.error('业务错误,请稍后再试');