Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error handling in components #1642

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

Elessar1802
Copy link
Contributor

@Elessar1802 Elessar1802 commented Feb 22, 2024

Description

An optional check is required since upon failure of the preceding api calls can return response objects without the result property field. (See fetchInTime & put) in devtron-fe-common-lib.

Added some missing catch blocks to api calls that can throw errors.

Fixed ResizeObserver loop finished with undelivered notifications error encountered upon resizing the window when the appDetails terminal is in view. Additionally refactored the code.

Future Work:

  • fetchApi in fe-common-lib returns [] as result instead of throwing an error. This causes code to run in Overview/Overview.tsx that shouldn't in such a case causing crash in line number 281.

Fixes devtron-labs/devtron#4710

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Test A
  • Test B

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

@github-actions github-actions bot added PR:Issue-verification-failed PR:Issue-verification-failed PR:Ready-to-Review PR:Ready-to-Review and removed PR:Issue-verification-failed PR:Issue-verification-failed PR:Ready-to-Review PR:Ready-to-Review labels Feb 22, 2024
@Elessar1802 Elessar1802 added PR:Ready-to-Review PR:Ready-to-Review and removed PR:Issue-verification-failed PR:Issue-verification-failed labels Feb 22, 2024
@Elessar1802 Elessar1802 changed the title fix: Add optional chaining in DeploymentTemplateOverrideForm.tsx fix: better error handling Feb 22, 2024
@Elessar1802 Elessar1802 changed the title fix: better error handling fix: better error handling in case of 400-499 errors Feb 22, 2024
@Elessar1802 Elessar1802 changed the title fix: better error handling in case of 400-499 errors fix: better error handling in components Feb 27, 2024
@@ -1112,32 +1112,6 @@ export const reloadToastBody = () => {
)
}

export function useHeightObserver(callback): [RefObject<HTMLDivElement>] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents of the custom hook seem a little convoluted and unnecessary to me. Since this is (was) being used only in TerminalView, I have refactored it out. React warns us from using useLayoutEffect anyways. The motive was probably that the actually resizing should be differed to the next repaint to prevent infinite loops in ResizeObserver callback. We shouldn't change the div size inside the resizeObserver. Thus using window.requestAnimationFrame will defer the actual resize until the next repaint saving us from the infinite resize.

src/components/app/details/appDetails/AppDetails.tsx Outdated Show resolved Hide resolved
src/components/app/details/main.tsx Outdated Show resolved Hide resolved
src/components/app/details/main.tsx Outdated Show resolved Hide resolved
src/components/app/details/triggerView/TriggerView.tsx Outdated Show resolved Hide resolved
src/components/login/Login.tsx Outdated Show resolved Hide resolved
src/components/v2/appDetails/AppDetails.component.tsx Outdated Show resolved Hide resolved
@@ -518,7 +518,7 @@ export default function DeploymentConfig({
const deploymentTemplateResp = isProtected
? await checkForProtectedLockedChanges()
: await getIfLockedConfigNonProtected(requestBody)
if (deploymentTemplateResp.result.isLockConfigError) {
if (deploymentTemplateResp.result?.isLockConfigError) {
setDisableSaveEligibleChanges(deploymentTemplateResp.result?.disableSaveEligibleChanges)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vivek-devtron Do I need to remove these optional chaining checks on line 552 and 553?

@@ -566,7 +566,7 @@ export default function DeploymentConfig({
const requestBody = prepareDataToSave(true)
const api = state.chartConfig.id ? updateDeploymentTemplate : saveDeploymentTemplate
const deploymentTemplateResp = await api(requestBody, baseDeploymentAbortController.signal)
if (deploymentTemplateResp.result.isLockConfigError) {
if (deploymentTemplateResp.result?.isLockConfigError) {
setDisableSaveEligibleChanges(deploymentTemplateResp.result?.disableSaveEligibleChanges)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here?

@@ -216,6 +216,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
setDefaultConfig(_isDefaultConfig)
setConfigPresent(isConfigPresent)
})
.catch()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm with @arunjaindev

edit renderSideInfoColumn in EnvironmentOverview.tsx
edit in deploymentConfig/DeploymentConfig.tsx
Copy link

sonarcloud bot commented Mar 1, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Elessar1802 Elessar1802 self-assigned this Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR:Ready-to-Review PR:Ready-to-Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: error handlings on 400-599 responses and error on resizing of app detail terminal
3 participants