From f0a6820a01597caaf69dc784e8bd644b1792cf9d Mon Sep 17 00:00:00 2001 From: DebugIsFalse <511418503@qq.com> Date: Wed, 29 May 2024 11:42:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86open=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/search/[id].vue | 8 +++++++- utils/fetchEventSource.js | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pages/search/[id].vue b/pages/search/[id].vue index c0cdb8a..a438bef 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -244,12 +244,17 @@ const handleStopGenerate = () => { }) } const handleError = (event) => { - console.log('event:', event) + askingData.value = {} handleStopGenerate() if (event) { throw event } } +const handleOpen = (status) => { + if ([401, 403].includes(status)) { + askingData.value = {} + } +} const fetchLinkedQuestion = async (query) => { const { gitPath, id } = state const messages = [] @@ -279,6 +284,7 @@ const generateFetchData = (query) => { } fetchEventSource('/v1/chat/completions', { params , + onopen: handleOpen, onmessage: handleMessage, onerror: handleError, controller: aiChatController diff --git a/utils/fetchEventSource.js b/utils/fetchEventSource.js index 71add05..31ce8fa 100644 --- a/utils/fetchEventSource.js +++ b/utils/fetchEventSource.js @@ -1,6 +1,6 @@ import { fetchEventSource } from '@microsoft/fetch-event-source' const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run' -export default (url, { onmessage, onerror, controller, params }) => { +export default (url, { onmessage, onerror, controller, params, onopen }) => { const token = useCookie('token') fetchEventSource(`${BASE_URL}${url}`, { method: 'POST', @@ -13,6 +13,7 @@ export default (url, { onmessage, onerror, controller, params }) => { onopen (response) { const status = response.status useRequestError(status) + onopen(status) }, onmessage (info) { onmessage(info) -- GitLab