This commit is contained in:
“xHuPo” 2025-05-23 19:09:06 +08:00
parent bcd986e3f7
commit 44500afd3f
2 changed files with 41 additions and 15 deletions

View file

@ -24,19 +24,13 @@ const request = (options) => {
success: (res) => {
// 处理业务错误
if (res.data.code !== 0) {
// token过期尝试刷新
if (res.statusCode === 401) {
refreshToken().then(() => {
// 刷新token后重试请求
request(options).then(resolve).catch(reject);
}).catch((err) => {
// 刷新失败,需要重新登录
// token过期直接清除并跳转登录
if (res.statusCode === 401) {
wx.removeStorageSync('token');
wx.removeStorageSync('openid');
reject(err);
});
return;
}
reject(new Error('登录已过期,请重新登录'));
return;
}
reject(new Error(res.data.message || '请求失败'));
return;
}