Remove useless code (#4416)

This commit is contained in:
Garfield Dai
2024-05-15 16:14:49 +08:00
committed by GitHub
parent da81233d61
commit dd94931116
26 changed files with 466 additions and 230 deletions

View File

@@ -10,6 +10,7 @@ import type {
WorkflowFinishedResponse,
WorkflowStartedResponse,
} from '@/types/workflow'
import { removeAccessToken } from '@/app/components/share/utils'
const TIME_OUT = 100000
const ContentType = {
@@ -97,6 +98,10 @@ function unicodeToChar(text: string) {
})
}
function requiredWebSSOLogin() {
globalThis.location.href = `/webapp-signin?redirect_url=${globalThis.location.pathname}`
}
export function format(text: string) {
let res = text.trim()
if (res.startsWith('\n'))
@@ -308,6 +313,15 @@ const baseFetch = <T>(
return bodyJson.then((data: ResponseError) => {
if (!silent)
Toast.notify({ type: 'error', message: data.message })
if (data.code === 'web_sso_auth_required')
requiredWebSSOLogin()
if (data.code === 'unauthorized') {
removeAccessToken()
globalThis.location.reload()
}
return Promise.reject(data)
})
}
@@ -467,6 +481,16 @@ export const ssePost = (
if (!/^(2|3)\d{2}$/.test(String(res.status))) {
res.json().then((data: any) => {
Toast.notify({ type: 'error', message: data.message || 'Server Error' })
if (isPublicAPI) {
if (data.code === 'web_sso_auth_required')
requiredWebSSOLogin()
if (data.code === 'unauthorized') {
removeAccessToken()
globalThis.location.reload()
}
}
})
onError?.('Server Error')
return