Skip to content

Commit c8ac3d6

Browse files
committed
added payload validation and err handling
1 parent e245b3d commit c8ac3d6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

api/helm-app/service/HelmAppService.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devtron-labs/devtron/api/helm-app/models"
2828
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
2929
"github.com/devtron-labs/devtron/api/helm-app/service/read"
30+
"github.com/devtron-labs/devtron/api/restHandler/common"
3031
"github.com/devtron-labs/devtron/internal/constants"
3132
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
3233
bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean"
@@ -158,13 +159,22 @@ func GetHelmReleaseConfig() (*HelmReleaseConfig, error) {
158159
func (impl *HelmAppServiceImpl) ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool) {
159160
var helmCdPipelines []*pipelineConfig.Pipeline
160161
var installedHelmApps []*repository.InstalledApps
162+
if len(clusterIds) == 0 {
163+
common.WriteJsonResp(w, util.DefaultApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage("Invalid payload. Provide cluster ids in request").WithUserMessage("Invalid payload. Provide cluster ids in request"),
164+
nil,
165+
http.StatusBadRequest)
166+
return
167+
}
161168
start := time.Now()
162169
appStream, err := impl.listApplications(ctx, clusterIds)
163170
middleware.AppListingDuration.WithLabelValues("listApplications", "helm").Observe(time.Since(start).Seconds())
164171
if err != nil {
165172
impl.logger.Errorw("error in fetching app list", "clusters", clusterIds, "err", err)
166-
}
167-
if err == nil && len(clusterIds) > 0 {
173+
common.WriteJsonResp(w, util.DefaultApiError().WithHttpStatusCode(http.StatusInternalServerError).WithInternalMessage("error in fetching app list").WithUserMessage("error in fetching app list"),
174+
nil,
175+
http.StatusInternalServerError)
176+
return
177+
} else if len(clusterIds) > 0 {
168178
// get helm apps which are created using cd_pipelines
169179
newCtx, span := otel.Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
170180
start = time.Now()

0 commit comments

Comments
 (0)