This commit is contained in:
yanghao05
2025-04-29 10:15:36 +08:00
parent 75e39a0283
commit da8ad94eda
9 changed files with 232 additions and 35 deletions

View File

@@ -1,3 +1,4 @@
import router from '@/router';
import { useAuthStore } from '@/stores/auth';
import axios from 'axios';
@@ -32,7 +33,12 @@ httpClient.interceptors.response.use(
error => {
// Handle HTTP errors here
if (error.response) {
// Server responded with error status
// Handle 401 Unauthorized
if (error.response.status === 401) {
const authStore = useAuthStore();
authStore.logout();
router.push('/login');
}
console.error('API Error:', error.response.status, error.response.data);
} else if (error.request) {
// Request made but no response received