Skip to content

Commit

Permalink
Merge branch 'main' into chore-refactoring-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-exp committed Jan 18, 2024
2 parents ae90f36 + ad899a0 commit 6964081
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 6964081

Please sign in to comment.