From d9445ebb1582e295dadea422fcbd7be514a15fb8 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 5 Nov 2024 14:20:27 -0300 Subject: [PATCH] fix: server busy error even when the server is responding (#4403) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ (api.tsx): add utility store to manage health check timeout in the API interceptor 📝 (api.tsx): update comments in the code for better readability and understanding Co-authored-by: Gabriel Luiz Freitas Almeida --- src/frontend/src/controllers/API/api.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index 083d41c0d..c7fb37a11 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -1,6 +1,7 @@ import { LANGFLOW_ACCESS_TOKEN } from "@/constants/constants"; import { useCustomApiHeaders } from "@/customization/hooks/use-custom-api-headers"; import useAuthStore from "@/stores/authStore"; +import { useUtilityStore } from "@/stores/utilityStore"; import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios"; import * as fetchIntercept from "fetch-intercept"; import { useEffect } from "react"; @@ -33,6 +34,10 @@ function ApiInterceptor() { const isLoginPage = location.pathname.includes("login"); const customHeaders = useCustomApiHeaders(); + const setHealthCheckTimeout = useUtilityStore( + (state) => state.setHealthCheckTimeout, + ); + useEffect(() => { const unregister = fetchIntercept.register({ request: function (url, config) { @@ -49,7 +54,10 @@ function ApiInterceptor() { }); const interceptor = api.interceptors.response.use( - (response) => response, + (response) => { + setHealthCheckTimeout(null); + return response; + }, async (error: AxiosError) => { const isAuthenticationError = error?.response?.status === 403 || error?.response?.status === 401;