From 1d03d9c8723875eced4e400d5dda7156310d2c0b Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Mon, 4 Apr 2022 13:01:25 +0000 Subject: [PATCH] handle case that GetClusters returns empty list --- pkg/cluster/accessor.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/accessor.go b/pkg/cluster/accessor.go index a20c45c..7a67414 100644 --- a/pkg/cluster/accessor.go +++ b/pkg/cluster/accessor.go @@ -42,15 +42,20 @@ func (x *ClusterAccessor) GetClustersByContractID(contractId uuid.UUID) ([]*pb.C res := x.db.Find(&clusters, "contract_id = ?", contractId) - if res.RowsAffected == 0 || res.Error != nil { - return nil, fmt.Errorf("Could not find clusters with contractID: %s", contractId) + if res.Error != nil { + return nil, fmt.Errorf("Error while finding clusters with contractID: %s", contractId) } pbClusters := []*pb.Cluster{} + + // If no record is found, just return empty array. + if res.RowsAffected == 0 { + return pbClusters, nil + } + for _, cluster := range clusters { pbClusters = append(pbClusters, ConvertToPbCluster(cluster)) } - return pbClusters, nil }