Skip to content

Commit

Permalink
chore: add error details in push topology
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Sep 11, 2024
1 parent e6b2e39 commit 3a6769d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions push/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

dutyAPI "github.com/flanksource/duty/api"
"github.com/flanksource/duty/context"
dutydb "github.com/flanksource/duty/db"
"github.com/flanksource/duty/models"
"github.com/flanksource/incident-commander/db"
"github.com/google/uuid"
Expand Down Expand Up @@ -49,7 +50,7 @@ func PushTopology(c echo.Context) error {
}

if err = topologyObj.Save(ctx.DB()); err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error persisting topology: %v", err))
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error persisting topology: %v", dutydb.ErrorDetails(err)))
}

data.AgentID = agentID
Expand All @@ -61,17 +62,17 @@ func PushTopology(c echo.Context) error {
}

if err := data.Save(ctx.DB()); err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error saving components: %v", err))
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error saving components: %v", dutydb.ErrorDetails(err)))
}

var idsToDelete []string
if err := ctx.DB().Model(&models.Component{}).Select("id").Where("topology_id = ?", data.TopologyID).Where("id NOT IN ?", compIDs).Find(&idsToDelete).Error; err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error querying old components: %v", err))
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error querying old components: %v", dutydb.ErrorDetails(err)))
}

if len(idsToDelete) > 0 {
if err := models.DeleteComponentsWithIDs(ctx.DB(), idsToDelete); err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error deleting old components: %v", err))
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error deleting old components: %v", dutydb.ErrorDetails(err)))
}
}

Expand Down

0 comments on commit 3a6769d

Please sign in to comment.