diff --git a/frontend/src/apiClient.js b/frontend/src/apiClient.js index 0c46f5c..c29713e 100644 --- a/frontend/src/apiClient.js +++ b/frontend/src/apiClient.js @@ -5,6 +5,13 @@ export const backendBaseUrl = import.meta.env.VITE_BACKEND || 'http://localhost: const apiClient = axios.create({ baseURL: `${backendBaseUrl}/api`, + timeout: 60000, // 60 Sekunden Timeout für Requests (länger für langsame Verbindungen) + // Erlaube längere Verbindungen + maxRedirects: 5, + validateStatus: function (status) { + // Behandle alle Status-Codes als gültig, damit wir sie selbst behandeln können + return status >= 200 && status < 600; + }, }); apiClient.interceptors.request.use(config => { @@ -25,6 +32,16 @@ apiClient.interceptors.request.use(config => { apiClient.interceptors.response.use( response => response, error => { + // Prüfe auf Netzwerkfehler (keine Response = Verbindungsproblem) + if (!error.response) { + // Wenn es ein Timeout oder Netzwerkfehler ist, nicht automatisch ausloggen + if (error.code === 'ECONNABORTED' || error.code === 'ERR_NETWORK' || error.message === 'Network Error') { + console.warn('[API Client] Netzwerkfehler oder Timeout:', error.message); + // Wirft den Fehler weiter, aber ohne automatisches Logout + return Promise.reject(error); + } + } + if (error.response && error.response.status === 401) { // Automatisch ausloggen und zur Login-Seite weiterleiten store.dispatch('logout');