Skip to content

Commit

Permalink
handle case that GetClusters returns empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
robertchoi80 committed Apr 4, 2022
1 parent 77e1e43 commit 1d03d9c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/cluster/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1d03d9c

Please sign in to comment.