From f54d8ccee6e08cd03066b34b306a8f7b3ba6ac04 Mon Sep 17 00:00:00 2001 From: Kaushik Narayan R Date: Tue, 7 Jan 2025 15:51:07 -0700 Subject: [PATCH] fix --- src/components/APIWrapper/index.tsx | 12 ++++++------ src/pages/Graph/index.tsx | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/APIWrapper/index.tsx b/src/components/APIWrapper/index.tsx index 6ddf35c..8a00a46 100644 --- a/src/components/APIWrapper/index.tsx +++ b/src/components/APIWrapper/index.tsx @@ -30,29 +30,29 @@ const APIWrapper = async ({ data, config, }: APIWrapperProps) => { + let apiResp; for (let i = 1; i <= maxRetries + 1; i++) { - const apiResp = await apiFn(data, config); + apiResp = await apiFn(data, config); if (apiResp === undefined) { showErrorToastNotification("Please try again after sometime"); } else if (apiResp.status >= 200 && apiResp.status < 300) { - return apiResp; + break; } else if (apiResp.status === 401) { showWarnToastNotification("Session expired, refreshing..."); if (!(await refreshAuth())) { showErrorToastNotification("Session invalid."); - return; + break; } } else if (apiResp.status >= 400 && apiResp.status < 500) { showErrorToastNotification(apiResp.data.message); - return; // no retry on 4XX + break; // no retry on 4XX } else { showErrorToastNotification(apiResp.data.message); } await sleep(i * i * 1000); } - showErrorToastNotification("Please try again after sometime"); - return; + return apiResp; }; export default APIWrapper; diff --git a/src/pages/Graph/index.tsx b/src/pages/Graph/index.tsx index e6e717f..1d9aded 100644 --- a/src/pages/Graph/index.tsx +++ b/src/pages/Graph/index.tsx @@ -164,7 +164,6 @@ const Graph = () => { const onConnect: OnConnect = useCallback( async (connection) => { - setLinkEdges((eds) => addEdge(connection, eds)); console.debug( `new connection: ${connection.source} -> ${connection.target}` ); @@ -178,8 +177,10 @@ const Graph = () => { }, refreshAuth, }); - if (resp?.status === 201) + if (resp?.status === 201) { showSuccessToastNotification(resp?.data.message); + setLinkEdges((eds) => addEdge(connection, eds)); + } }, [setLinkEdges, refreshAuth] );