对接接口
This commit is contained in:
@ -32,7 +32,7 @@ const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthenticati
|
||||
}
|
||||
catch (error) {
|
||||
// 切换到登录页
|
||||
await uni.reLaunch({ url: '/pages/login/login' })
|
||||
await uni.reLaunch({ url: import.meta.env.VITE_LOGIN_URL })
|
||||
throw error
|
||||
}
|
||||
},
|
||||
@ -58,19 +58,13 @@ const alovaInstance = createAlova({
|
||||
|
||||
const { config } = method
|
||||
const ignoreAuth = !config.meta?.ignoreAuth
|
||||
console.log('ignoreAuth===>', ignoreAuth)
|
||||
|
||||
// 处理认证信息 自行处理认证问题
|
||||
if (ignoreAuth) {
|
||||
// const token = 'getToken()'
|
||||
// if (!token) {
|
||||
// throw new Error('[请求错误]:未登录')
|
||||
// }
|
||||
// method.config.headers.token = token;
|
||||
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
toast.info('请先登录')
|
||||
router.switchTab('/pages/my/my', 500)
|
||||
router.switchTab(import.meta.env.VITE_LOGIN_URL, 500)
|
||||
throw new Error('[请求错误]:未登录')
|
||||
}
|
||||
|
||||
@ -98,14 +92,6 @@ const alovaInstance = createAlova({
|
||||
return response
|
||||
}
|
||||
|
||||
// 处理 HTTP 状态码错误
|
||||
// if (statusCode !== 200) {
|
||||
// const errorMessage = ShowMessage(statusCode) || `HTTP请求错误[${statusCode}]`
|
||||
// console.error('errorMessage===>', errorMessage)
|
||||
// toast.error(errorMessage)
|
||||
// throw new Error(`${errorMessage}:${errMsg}`)
|
||||
// }
|
||||
|
||||
// 处理业务逻辑错误
|
||||
const { code, msg, data } = rawData as IResponse
|
||||
if (code === ResultEnum.Unauthorized) {
|
||||
@ -114,7 +100,7 @@ const alovaInstance = createAlova({
|
||||
|
||||
if (config.meta?.toast !== false) {
|
||||
toast.info(msg)
|
||||
router.switchTab('/pages/my/my', 1000)
|
||||
router.switchTab(import.meta.env.VITE_LOGIN_URL, 1000)
|
||||
}
|
||||
throw new Error(`登录超时[${code}]:${msg}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user