fix(entry): add entry
This commit is contained in:
37
api/fetch.ts
37
api/fetch.ts
@@ -156,7 +156,6 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
||||
}
|
||||
} else {
|
||||
const { status } = response
|
||||
|
||||
if (status === 400) {
|
||||
if (
|
||||
response.headers.get("Content-Type")?.includes("application/json")
|
||||
@@ -170,6 +169,42 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
||||
Message.error({ content: errInfo || "" })
|
||||
throw new Error(errInfo)
|
||||
}
|
||||
} else if (status === 401) {
|
||||
try {
|
||||
const refreshResponse = await refreshKey({
|
||||
token: refresh_token,
|
||||
})
|
||||
if (refreshResponse.code === 200) {
|
||||
let access_token = refreshResponse.message?.access || ""
|
||||
let refresh_token = refreshResponse.message?.refresh || ""
|
||||
refreshToken({
|
||||
refresh_token,
|
||||
access_token,
|
||||
})
|
||||
const retry_request = createNewRequest(options, access_token)
|
||||
const retry_response = await fetch(retry_request)
|
||||
return options.isDownload
|
||||
? retry_response.blob()
|
||||
: retry_response.json()
|
||||
} else {
|
||||
const { code } = refreshResponse
|
||||
if (code === 406) {
|
||||
try {
|
||||
await deleteCookie()
|
||||
} catch (error) {
|
||||
rejected(error)
|
||||
} finally {
|
||||
// 清空身份信息并跳转至登录页面
|
||||
removeUserInfo()
|
||||
window.location.href = "/login"
|
||||
}
|
||||
} else {
|
||||
throw new Error("重新获取token失败!")
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
rejected(error)
|
||||
}
|
||||
} else if (status === 403) {
|
||||
if (
|
||||
response.headers.get("Content-Type")?.includes("application/json")
|
||||
|
||||
Reference in New Issue
Block a user