BUG fix: requestRefresh
This commit is contained in:
parent
68b97d0162
commit
a4d134bc05
|
@ -15,7 +15,11 @@ interface ErrorResponseData {
|
|||
*/
|
||||
export const onRequestError = async (response: Response) => {
|
||||
if (response.status === 401) {
|
||||
Message('Unauthorized', '未认证', 'error')
|
||||
Message(
|
||||
'Login expired, please log in again.',
|
||||
'登陆过期,请重新登陆',
|
||||
'error'
|
||||
)
|
||||
useKUNGalgameUserStore().removeToken()
|
||||
router.push('/login')
|
||||
return
|
||||
|
|
|
@ -29,7 +29,7 @@ const kunFetchRequest = async <T>(
|
|||
const newResponseData = await requestRefresh(fullUrl, options)
|
||||
const data: T = await newResponseData.json()
|
||||
return data
|
||||
} else if (response.status === 233) {
|
||||
} else if (response.status === 233 || !response.ok) {
|
||||
// Handle some known backend error
|
||||
await onRequestError(response)
|
||||
return {} as T
|
||||
|
|
|
@ -10,17 +10,7 @@ export const requestRefresh = async (
|
|||
) => {
|
||||
const accessTokenResponse = await generateTokenByRefreshTokenApi()
|
||||
|
||||
if (accessTokenResponse.code === 200 && accessTokenResponse.data.token) {
|
||||
useKUNGalgameUserStore().setToken(accessTokenResponse.data.token)
|
||||
} else {
|
||||
Message(
|
||||
'Login expired, please log in again.',
|
||||
'登陆过期,请重新登陆',
|
||||
'error'
|
||||
)
|
||||
useKUNGalgameUserStore().removeToken()
|
||||
router.push('/login')
|
||||
}
|
||||
useKUNGalgameUserStore().setToken(accessTokenResponse.data.token)
|
||||
|
||||
const headers = {
|
||||
...options.headers,
|
||||
|
|
Loading…
Reference in a new issue