This commit is contained in:
Kaushik Narayan R 2025-01-07 15:51:07 -07:00
parent d7addccbc7
commit f54d8ccee6
2 changed files with 9 additions and 8 deletions

View File

@ -30,29 +30,29 @@ const APIWrapper = async <T extends apiRespBaseType>({
data, data,
config, config,
}: APIWrapperProps<T>) => { }: APIWrapperProps<T>) => {
let apiResp;
for (let i = 1; i <= maxRetries + 1; i++) { for (let i = 1; i <= maxRetries + 1; i++) {
const apiResp = await apiFn(data, config); apiResp = await apiFn(data, config);
if (apiResp === undefined) { if (apiResp === undefined) {
showErrorToastNotification("Please try again after sometime"); showErrorToastNotification("Please try again after sometime");
} else if (apiResp.status >= 200 && apiResp.status < 300) { } else if (apiResp.status >= 200 && apiResp.status < 300) {
return apiResp; break;
} else if (apiResp.status === 401) { } else if (apiResp.status === 401) {
showWarnToastNotification("Session expired, refreshing..."); showWarnToastNotification("Session expired, refreshing...");
if (!(await refreshAuth())) { if (!(await refreshAuth())) {
showErrorToastNotification("Session invalid."); showErrorToastNotification("Session invalid.");
return; break;
} }
} else if (apiResp.status >= 400 && apiResp.status < 500) { } else if (apiResp.status >= 400 && apiResp.status < 500) {
showErrorToastNotification(apiResp.data.message); showErrorToastNotification(apiResp.data.message);
return; // no retry on 4XX break; // no retry on 4XX
} else { } else {
showErrorToastNotification(apiResp.data.message); showErrorToastNotification(apiResp.data.message);
} }
await sleep(i * i * 1000); await sleep(i * i * 1000);
} }
showErrorToastNotification("Please try again after sometime"); return apiResp;
return;
}; };
export default APIWrapper; export default APIWrapper;

View File

@ -164,7 +164,6 @@ const Graph = () => {
const onConnect: OnConnect = useCallback( const onConnect: OnConnect = useCallback(
async (connection) => { async (connection) => {
setLinkEdges((eds) => addEdge(connection, eds));
console.debug( console.debug(
`new connection: ${connection.source} -> ${connection.target}` `new connection: ${connection.source} -> ${connection.target}`
); );
@ -178,8 +177,10 @@ const Graph = () => {
}, },
refreshAuth, refreshAuth,
}); });
if (resp?.status === 201) if (resp?.status === 201) {
showSuccessToastNotification(resp?.data.message); showSuccessToastNotification(resp?.data.message);
setLinkEdges((eds) => addEdge(connection, eds));
}
}, },
[setLinkEdges, refreshAuth] [setLinkEdges, refreshAuth]
); );