Skip to content

Commit 0e53c1c

Browse files
committed
feat: implement handledFirstCall to manage error response codes in API calls
1 parent ce331b3 commit 0e53c1c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/components/externalArgoApps/ExternalArgoAppDetail.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DeploymentAppTypes,
2525
getIsRequestAborted,
2626
abortPreviousRequests,
27+
API_STATUS_CODES,
2728
} from '@devtron-labs/devtron-fe-common-lib'
2829
import { getArgoAppDetail } from '../external-apps/ExternalAppService'
2930
import { checkIfToRefetchData, deleteRefetchDataFromUrl } from '../util/URLUtil'
@@ -41,6 +42,8 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
4142
const [isReloadResourceTreeInProgress, setIsReloadResourceTreeInProgress] = useState(false)
4243
const [errorResponseCode, setErrorResponseCode] = useState(undefined)
4344

45+
const handledFirstCall = useRef(false)
46+
4447
let isAPICallInProgress = false
4548

4649
const abortControllerRef = useRef<AbortController>(new AbortController())
@@ -114,7 +117,11 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
114117
.catch((errors: ServerErrors) => {
115118
if (!getIsRequestAborted(errors)) {
116119
showError(errors)
117-
setErrorResponseCode(errors.code)
120+
121+
if (!handledFirstCall.current || errors.code === API_STATUS_CODES.NOT_FOUND) {
122+
setErrorResponseCode(errors.code)
123+
}
124+
118125
isAPICallInProgress = false
119126
handleInitiatePolling()
120127
}
@@ -123,6 +130,7 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
123130
setIsLoading(false)
124131
isAPICallInProgress = false
125132
setIsReloadResourceTreeInProgress(false)
133+
handledFirstCall.current = true
126134
})
127135
}
128136

src/components/v2/appDetails/ea/EAAppDetail.component.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DeploymentAppTypes,
2525
getIsRequestAborted,
2626
abortPreviousRequests,
27+
API_STATUS_CODES,
2728
} from '@devtron-labs/devtron-fe-common-lib'
2829
import moment from 'moment'
2930
import { sortOptionsByValue } from '../../../common'
@@ -54,6 +55,7 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
5455
const [isReloadResourceTreeInProgress, setIsReloadResourceTreeInProgress] = useState(false)
5556

5657
const abortControllerRef = useRef<AbortController>(new AbortController())
58+
const handledFirstCall = useRef(false)
5759

5860
let isAPICallInProgress = false
5961

@@ -189,12 +191,15 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
189191

190192
if (!getIsRequestAborted(errors)) {
191193
showError(errors)
192-
setErrorResponseCode(errors.code)
194+
if (!handledFirstCall.current || errors.code === API_STATUS_CODES.NOT_FOUND) {
195+
setErrorResponseCode(errors.code)
196+
}
193197
handleInitiatePolling()
194198
}
195199
})
196200
.finally(() => {
197201
setIsReloadResourceTreeInProgress(false)
202+
handledFirstCall.current = true
198203
})
199204
}
200205

src/components/v2/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Redirect, Route, Switch, useHistory, useLocation, useParams, useRouteMa
1919

2020
import {
2121
abortPreviousRequests,
22+
API_STATUS_CODES,
2223
DetailsProgressing,
2324
ErrorScreenManager,
2425
getIsRequestAborted,
@@ -64,6 +65,7 @@ const RouterComponent = () => {
6465
const [isReloadResourceTreeInProgress, setIsReloadResourceTreeInProgress] = useState(false)
6566
const appDetailsRef = useRef({} as AppDetails)
6667
const isVirtualRef = useRef(false)
68+
const handledFirstCall = useRef(false)
6769

6870
useEffect(() => {
6971
IndexStore.setEnvDetails(EnvType.CHART, +params.appId, +params.envId)
@@ -126,8 +128,11 @@ const RouterComponent = () => {
126128
return
127129
}
128130

129-
setErrorResponseCode(e.code)
130-
if (e.code === 404 && initTimer) {
131+
if (!handledFirstCall.current || e.code === API_STATUS_CODES.NOT_FOUND) {
132+
setErrorResponseCode(e.code)
133+
}
134+
135+
if (e.code === API_STATUS_CODES.NOT_FOUND && initTimer) {
131136
clearTimeout(initTimer)
132137
}
133138
}
@@ -204,6 +209,8 @@ const RouterComponent = () => {
204209
if (!isAborted) {
205210
handleInitiatePolling()
206211
}
212+
}).finally(() => {
213+
handledFirstCall.current = true
207214
})
208215
}
209216

0 commit comments

Comments
 (0)