Skip to content

Commit

Permalink
fix: resource tree err handling (#4530)
Browse files Browse the repository at this point in the history
* improved error handling for resource tree

* added return to avoid multiple writes
  • Loading branch information
kartik-579 authored and Ash-exp committed Jan 22, 2024
1 parent cc91cc4 commit d4ea0e5
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions api/restHandler/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,22 +1024,36 @@ func (handler AppListingRestHandlerImpl) FetchResourceTree(w http.ResponseWriter
return
}
resourceTree, err := handler.fetchResourceTree(w, r, appId, envId, acdToken, cdPipeline)
if err != nil {
handler.logger.Errorw("error in fetching resource tree", "err", err, "appId", appId, "envId", envId)
handler.handleResourceTreeErrAndDeletePipelineIfNeeded(w, err, appId, envId, acdToken, cdPipeline)
return
}
common.WriteJsonResp(w, err, resourceTree, http.StatusOK)
}

func (handler AppListingRestHandlerImpl) handleResourceTreeErrAndDeletePipelineIfNeeded(w http.ResponseWriter, err error,
appId int, envId int, acdToken string, cdPipeline *pipelineConfig.Pipeline) {
if cdPipeline.DeploymentAppType == util.PIPELINE_DEPLOYMENT_TYPE_ACD {
apiError, ok := err.(*util.ApiError)
if ok && apiError != nil {
if apiError.Code == constants.AppDetailResourceTreeNotFound && cdPipeline.DeploymentAppDeleteRequest == true && cdPipeline.DeploymentAppCreated == true {
acdAppFound, _ := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId, envId, acdToken, cdPipeline)
if acdAppFound {
common.WriteJsonResp(w, fmt.Errorf("unable to fetch resource tree"), nil, http.StatusInternalServerError)
acdAppFound, appDeleteErr := handler.pipeline.MarkGitOpsDevtronAppsDeletedWhereArgoAppIsDeleted(appId, envId, acdToken, cdPipeline)
if appDeleteErr != nil {
common.WriteJsonResp(w, fmt.Errorf("error in deleting devtron pipeline for deleted argocd app"), nil, http.StatusInternalServerError)
return
} else {
common.WriteJsonResp(w, fmt.Errorf("app deleted"), nil, http.StatusNotFound)
} else if appDeleteErr == nil && !acdAppFound {
common.WriteJsonResp(w, fmt.Errorf("argocd app deleted"), nil, http.StatusNotFound)
return
}
}
}
}
common.WriteJsonResp(w, err, resourceTree, http.StatusOK)
//not returned yet therefore no specific error to be handled, send error in internal message
common.WriteJsonResp(w, &util.ApiError{
InternalMessage: err.Error(),
UserMessage: "unable to fetch resource tree",
}, nil, http.StatusInternalServerError)
}

func (handler AppListingRestHandlerImpl) FetchAppTriggerView(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit d4ea0e5

Please sign in to comment.