Skip to content

Commit

Permalink
fix: set target options to error if it occurs
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Brecic <luka.brecic3@gmail.com>
  • Loading branch information
lbrecic committed Oct 24, 2024
1 parent d05d96a commit 56ca7fe
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/api/controllers/target/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ func ListTargets(ctx *gin.Context) {
for _, target := range targets {
p, err := server.ProviderManager.GetProvider(target.ProviderInfo.Name)
if err != nil {
ctx.AbortWithError(http.StatusNotFound, fmt.Errorf("provider not found: %w", err))
return
target.Options = err.Error()
continue
}

manifest, err := (*p).GetTargetManifest()
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to get provider manifest: %w", err))
return
target.Options = err.Error()
continue
}

var opts map[string]interface{}
err = json.Unmarshal([]byte(target.Options), &opts)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to unmarshal options: %w", err))
return
target.Options = err.Error()
continue
}

for name, property := range *manifest {
Expand All @@ -59,8 +59,8 @@ func ListTargets(ctx *gin.Context) {

updatedOptions, err := json.MarshalIndent(opts, "", " ")
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to marshal updated options: %w", err))
return
target.Options = err.Error()
continue
}

target.Options = string(updatedOptions)
Expand Down

0 comments on commit 56ca7fe

Please sign in to comment.