mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 06:57:13 +08:00
refactor: 💥 分离 HTTP 状态码和业务状态码
1.传输正常的情况下无论业务是否有异常,HTTP 状态码始终为 200 2.防止非 HTTPS 情况下出现运营商劫持(例如:404)
This commit is contained in:
@@ -46,20 +46,10 @@ axios.interceptors.response.use(
|
||||
) {
|
||||
return response;
|
||||
}
|
||||
|
||||
const res = response.data;
|
||||
if (res.success) {
|
||||
return res;
|
||||
}
|
||||
messageErrorWrapper({
|
||||
content: res.msg || '网络错误',
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
return Promise.reject(new Error(res.msg || '网络错误'));
|
||||
},
|
||||
(error) => {
|
||||
const { response } = error;
|
||||
const res = response.data;
|
||||
if ([401].includes(res.code) && response.config.url !== '/auth/user/info') {
|
||||
modalErrorWrapper({
|
||||
title: '确认退出',
|
||||
@@ -68,8 +58,8 @@ axios.interceptors.response.use(
|
||||
escToClose: false,
|
||||
okText: '重新登录',
|
||||
async onOk() {
|
||||
const userStore = useLoginStore();
|
||||
await userStore.logout();
|
||||
const loginStore = useLoginStore();
|
||||
await loginStore.logout();
|
||||
window.location.reload();
|
||||
},
|
||||
});
|
||||
@@ -79,6 +69,13 @@ axios.interceptors.response.use(
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
}
|
||||
return Promise.reject(new Error(res.msg || '网络错误'));
|
||||
},
|
||||
(error) => {
|
||||
messageErrorWrapper({
|
||||
content: error.msg || '网络错误',
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
@@ -117,7 +117,7 @@
|
||||
<a-drawer
|
||||
title="日志详情"
|
||||
:visible="visible"
|
||||
:width="580"
|
||||
:width="660"
|
||||
:footer="false"
|
||||
unmount-on-close
|
||||
render-to-body
|
||||
|
Reference in New Issue
Block a user