提交 7568a5cf 编写于 作者: D DebugIsFalse

fix: 403

上级 f0a6820a
...@@ -191,16 +191,24 @@ function handleFormatSource (source) { ...@@ -191,16 +191,24 @@ function handleFormatSource (source) {
} }
}) })
} }
function handleSetNoPermission () {
askingData.value = {}
useRequestError(403)
}
const handleFormFetchData = (fetchData) => { const handleFormFetchData = (fetchData) => {
let message = {} let message = {}
try { try {
message = JSON.parse(fetchData) message = JSON.parse(fetchData)
} catch(error) { } } catch(error) { }
if (Object.keys(message).length === 0) return if (Object.keys(message).length === 0) return
const { meta, choices, error } = message const { meta, choices, error, code } = message
nextTick(() => { nextTick(() => {
scrollToView() scrollToView()
}) })
// 处理403
if (error && code === 403) {
handleSetNoPermission()
}
// 不处理异常数据 // 不处理异常数据
if (!meta) { if (!meta) {
handleStopGenerate() handleStopGenerate()
......
import { fetchEventSource } from '@microsoft/fetch-event-source' import { fetchEventSource } from '@microsoft/fetch-event-source'
const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run' const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run'
// class PermissionError extends Error { }
export default (url, { onmessage, onerror, controller, params, onopen }) => { export default (url, { onmessage, onerror, controller, params, onopen }) => {
const token = useCookie('token') const token = useCookie('token')
fetchEventSource(`${BASE_URL}${url}`, { fetchEventSource(`${BASE_URL}${url}`, {
...@@ -14,6 +15,10 @@ export default (url, { onmessage, onerror, controller, params, onopen }) => { ...@@ -14,6 +15,10 @@ export default (url, { onmessage, onerror, controller, params, onopen }) => {
const status = response.status const status = response.status
useRequestError(status) useRequestError(status)
onopen(status) onopen(status)
// todo
// if ([401, 403].includes(status)) {
// throw new PermissionError();
// }
}, },
onmessage (info) { onmessage (info) {
onmessage(info) onmessage(info)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册