mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
fix(api): 优化401和403错误处理,增加403错误登出逻辑
This commit is contained in:
@@ -235,7 +235,7 @@ function createRequestClient(baseURL: string) {
|
||||
}
|
||||
|
||||
console.log('axiosResponseData', axiosResponseData);
|
||||
// 适配新的后端数据结构: { statusCode, data, succeeded, errors, extras, timestamp }
|
||||
// 适配后端数据结构: { statusCode, data, succeeded, errors, extras, timestamp }
|
||||
const { statusCode, data, succeeded, errors, extras, timestamp } =
|
||||
axiosResponseData;
|
||||
|
||||
@@ -261,13 +261,15 @@ function createRequestClient(baseURL: string) {
|
||||
// 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
|
||||
let timeoutMsg = '';
|
||||
switch (statusCode) {
|
||||
case 401: {
|
||||
case 401:
|
||||
case 403: {
|
||||
// 已经在登出过程中 不再执行
|
||||
if (isLogoutProcessing) {
|
||||
throw new UnauthorizedException(timeoutMsg);
|
||||
}
|
||||
isLogoutProcessing = true;
|
||||
const _msg = $t('http.loginTimeout');
|
||||
const _msg =
|
||||
typeof errors === 'string' ? errors : $t('http.loginTimeout');
|
||||
const userStore = useAuthStore();
|
||||
userStore.logout().finally(() => {
|
||||
message.error(_msg);
|
||||
|
||||
Reference in New Issue
Block a user