From 7568a5cf57e52cc91c8c75454d759cd46c312351 Mon Sep 17 00:00:00 2001 From: DebugIsFalse <511418503@qq.com> Date: Wed, 29 May 2024 14:25:39 +0800 Subject: [PATCH] fix: 403 --- pages/search/[id].vue | 10 +++++++++- utils/fetchEventSource.js | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pages/search/[id].vue b/pages/search/[id].vue index a438bef..a41c655 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -191,16 +191,24 @@ function handleFormatSource (source) { } }) } +function handleSetNoPermission () { + askingData.value = {} + useRequestError(403) +} const handleFormFetchData = (fetchData) => { let message = {} try { message = JSON.parse(fetchData) } catch(error) { } if (Object.keys(message).length === 0) return - const { meta, choices, error } = message + const { meta, choices, error, code } = message nextTick(() => { scrollToView() }) + // 处理403 + if (error && code === 403) { + handleSetNoPermission() + } // 不处理异常数据 if (!meta) { handleStopGenerate() diff --git a/utils/fetchEventSource.js b/utils/fetchEventSource.js index 31ce8fa..3ed8582 100644 --- a/utils/fetchEventSource.js +++ b/utils/fetchEventSource.js @@ -1,5 +1,6 @@ import { fetchEventSource } from '@microsoft/fetch-event-source' const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run' +// class PermissionError extends Error { } export default (url, { onmessage, onerror, controller, params, onopen }) => { const token = useCookie('token') fetchEventSource(`${BASE_URL}${url}`, { @@ -14,6 +15,10 @@ export default (url, { onmessage, onerror, controller, params, onopen }) => { const status = response.status useRequestError(status) onopen(status) + // todo + // if ([401, 403].includes(status)) { + // throw new PermissionError(); + // } }, onmessage (info) { onmessage(info) -- GitLab