From 3153dea99c33badbd7cf2d3b4825af21b94852ad Mon Sep 17 00:00:00 2001 From: mgianluc Date: Wed, 8 May 2024 09:43:09 +0200 Subject: [PATCH] When there are no result, return empty array A check on skip value (when no results are available) was causing thr query to return a 400 error. This PR fixes that. --- internal/server/addons.go | 8 ++++++++ internal/server/managed_clusters.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/internal/server/addons.go b/internal/server/addons.go index 01ccb22..0186d3d 100644 --- a/internal/server/addons.go +++ b/internal/server/addons.go @@ -274,6 +274,10 @@ func addDeployedResourcesForFeature(profileName string, } func getHelmReleaseInRange(helmReleases []HelmRelease, limit, skip int) ([]HelmRelease, error) { + if len(helmReleases) == 0 { + return helmReleases, nil + } + if skip < 0 { return nil, errors.New("skip cannot be negative") } @@ -295,6 +299,10 @@ func getHelmReleaseInRange(helmReleases []HelmRelease, limit, skip int) ([]HelmR } func getResourcesInRange(resources []Resource, limit, skip int) ([]Resource, error) { + if len(resources) == 0 { + return resources, nil + } + if skip < 0 { return nil, errors.New("skip cannot be negative") } diff --git a/internal/server/managed_clusters.go b/internal/server/managed_clusters.go index 6b89abc..d77dfd1 100644 --- a/internal/server/managed_clusters.go +++ b/internal/server/managed_clusters.go @@ -47,6 +47,10 @@ func (s ManagedClusters) Less(i, j int) bool { } func getClustersInRange(clusters ManagedClusters, limit, skip int) (ManagedClusters, error) { + if len(clusters) == 0 { + return clusters, nil + } + if skip < 0 { return nil, errors.New("skip cannot be negative") }