fix:优化页面
This commit is contained in:
@@ -25,11 +25,22 @@ apiClient.interceptors.request.use((config) => {
|
||||
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
async (error) => {
|
||||
if (error.response) {
|
||||
console.error('API error', error.response.status, error.response.data);
|
||||
if (error.response.status === 401) {
|
||||
const authStore = useAuthStore();
|
||||
// 避免刷新递归:标记本次请求是否已重试
|
||||
const original = error.config as any;
|
||||
if (!original._retry) {
|
||||
original._retry = true;
|
||||
const ok = await authStore.refresh();
|
||||
if (ok && authStore.accessToken) {
|
||||
original.headers = original.headers || {};
|
||||
original.headers.Authorization = `Bearer ${authStore.accessToken}`;
|
||||
return apiClient(original);
|
||||
}
|
||||
}
|
||||
authStore.clearSession();
|
||||
const current = router.currentRoute.value;
|
||||
if (!current.path.startsWith('/auth')) {
|
||||
|
||||
Reference in New Issue
Block a user