From de907df09273f4ee7c2cae182555af9545277427 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 17 Nov 2025 11:54:38 +0100 Subject: [PATCH] Enhance API client configuration with timeout and error handling improvements This commit updates the API client configuration to include a 60-second timeout for requests, allows for a maximum of 5 redirects, and modifies the status validation to handle all status codes. Additionally, it improves error handling by checking for network errors and preventing automatic logout on timeouts or network issues, enhancing the robustness of the API interactions. --- frontend/src/apiClient.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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');