From a98b86a991385ad0e8c86092e90c96155e91b235 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Wed, 29 May 2024 11:11:12 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(api.tsx):=20fix=20syntax=20erro?= =?UTF-8?q?rs=20in=20API=20interceptor=20to=20ensure=20proper=20error=20ha?= =?UTF-8?q?ndling=20and=20request=20rejection=20=F0=9F=92=A1=20(api.tsx):?= =?UTF-8?q?=20improve=20error=20message=20for=20duplicate=20requests=20to?= =?UTF-8?q?=20provide=20more=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/controllers/API/api.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index 529a2f623..c4c069ac9 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -47,7 +47,7 @@ function ApiInterceptor() { } await clearBuildVerticesState(error); return Promise.reject(error); - }, + } ); const isAuthorizedURL = (url) => { @@ -64,10 +64,10 @@ function ApiInterceptor() { const parsedURL = new URL(url); const isDomainAllowed = authorizedDomains.some( - (domain) => parsedURL.origin === new URL(domain).origin, + (domain) => parsedURL.origin === new URL(domain).origin ); const isEndpointAllowed = authorizedEndpoints.some((endpoint) => - parsedURL.pathname.includes(endpoint), + parsedURL.pathname.includes(endpoint) ); return isDomainAllowed || isEndpointAllowed; @@ -87,7 +87,11 @@ function ApiInterceptor() { config?.url !== "/health" && config?.method === "get" ) { - return Promise.reject("Duplicate request"); + return Promise.reject(` + Duplicate request detected. + URL: ${config.url} + Method: ${config.method} + `); } localStorage.setItem("lastUrlCalled", config.url ?? ""); @@ -101,7 +105,7 @@ function ApiInterceptor() { }, (error) => { return Promise.reject(error); - }, + } ); return () => { @@ -133,7 +137,7 @@ function ApiInterceptor() { if (error?.config?.headers) { delete error.config.headers["Authorization"]; error.config.headers["Authorization"] = `Bearer ${cookies.get( - "access_token_lf", + "access_token_lf" )}`; const response = await axios.request(error.config); return response;