Skip to content

Commit 60fbcec

Browse files
committed
refactor: integrate abort controller into external flux app details and enhance error handling
1 parent 5785688 commit 60fbcec

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/Pages/App/Details/ExternalFlux/ExternalFluxAppDetails.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useState } from 'react'
17+
import { useEffect, useRef, useState } from 'react'
1818
import { useParams } from 'react-router-dom'
1919

2020
import {
2121
AppType,
2222
DeploymentAppTypes,
2323
ERROR_STATUS_CODE,
2424
ErrorScreenManager,
25+
getIsRequestAborted,
2526
IndexStore,
2627
noop,
2728
ResponseType,
@@ -46,6 +47,15 @@ const ExternalFluxAppDetails = () => {
4647
const [isReloadResourceTreeInProgress, setIsReloadResourceTreeInProgress] = useState(true)
4748
const [appDetailsError, setAppDetailsError] = useState(null)
4849

50+
const abortControllerRef = useRef<AbortController>(new AbortController())
51+
52+
useEffect(
53+
() => () => {
54+
abortControllerRef.current.abort()
55+
},
56+
[],
57+
)
58+
4959
const handleUpdateIndexStoreWithDetails = (response: ResponseType<any>) => {
5060
const genericAppDetail: AppDetails = {
5161
...response.result,
@@ -63,13 +73,15 @@ const ExternalFluxAppDetails = () => {
6373
new Promise<void>((resolve) => {
6474
setIsReloadResourceTreeInProgress(true)
6575

66-
getExternalFluxCDAppDetails(clusterId, namespace, appName, isKustomization)
76+
getExternalFluxCDAppDetails(clusterId, namespace, appName, isKustomization, abortControllerRef)
6777
.then(handleUpdateIndexStoreWithDetails)
6878
.catch((error) => {
69-
if (!initialLoading) {
70-
showError(error)
71-
} else {
72-
setAppDetailsError(error)
79+
if (!getIsRequestAborted(error)) {
80+
if (!initialLoading) {
81+
showError(error)
82+
} else {
83+
setAppDetailsError(error)
84+
}
7385
}
7486
})
7587
.finally(() => {

src/Pages/App/Details/ExternalFlux/service.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { get, getUrlWithSearchParams } from '@devtron-labs/devtron-fe-common-lib'
17+
import { APIOptions, get, getUrlWithSearchParams } from '@devtron-labs/devtron-fe-common-lib'
1818

1919
import { Routes } from '../../../../config'
2020

21-
export const getExternalFluxCDAppDetails = (clusterId, namespace, appName, isKustomization) => {
21+
export const getExternalFluxCDAppDetails = async (
22+
clusterId,
23+
namespace,
24+
appName,
25+
isKustomization,
26+
abortControllerRef?: APIOptions['abortControllerRef'],
27+
) => {
2228
const appId = `${clusterId}|${namespace}|${appName}|${isKustomization}`
2329
const baseurl = `${Routes.FLUX_APPS}/${Routes.APP}`
2430
const params = {
2531
appId,
2632
}
33+
2734
const url = getUrlWithSearchParams(baseurl, params)
28-
return get(url)
35+
return get(url, { abortControllerRef })
2936
}

0 commit comments

Comments
 (0)