From 989ec611c634bf1c87b3a469c0ef7acc872d9806 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 16:50:24 -0600 Subject: [PATCH 1/2] Added response body into error messages --- pkg/client/smd.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/client/smd.go b/pkg/client/smd.go index 69fbf17..a908729 100644 --- a/pkg/client/smd.go +++ b/pkg/client/smd.go @@ -40,7 +40,11 @@ func (c SmdClient) Add(data HTTPBody, headers HTTPHeader) error { if res != nil { statusOk := res.StatusCode >= 200 && res.StatusCode < 300 if !statusOk { - return fmt.Errorf("returned status code %d when adding endpoint", res.StatusCode) + if len(body) > 0 { + return fmt.Errorf("%d: %s", res.StatusCode, string(body)) + } else { + return fmt.Errorf("returned status code %d when adding endpoint", res.StatusCode) + } } fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body)) } @@ -57,7 +61,11 @@ func (c SmdClient) Update(data HTTPBody, headers HTTPHeader) error { if res != nil { statusOk := res.StatusCode >= 200 && res.StatusCode < 300 if !statusOk { - return fmt.Errorf("failed to update redfish endpoint (returned %s)", res.Status) + if len(body) > 0 { + return fmt.Errorf("%d: %s", res.StatusCode, string(body)) + } else { + return fmt.Errorf("failed to update redfish endpoint (returned %s)", res.Status) + } } fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body)) } From 2e036c549d359650681e9cd4bf598cd8f6564cb6 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 16:55:07 -0600 Subject: [PATCH 2/2] Rearranged collect error to only show when not force updating --- internal/collect.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/collect.go b/internal/collect.go index 9c123c3..ea7ca69 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -150,7 +150,6 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error { if smdClient.URI != "" { err = smdClient.Add(body, headers) if err != nil { - log.Error().Err(err).Msgf("failed to add Redfish endpoint") // try updating instead if params.ForceUpdate { @@ -159,6 +158,8 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error { if err != nil { log.Error().Err(err).Msgf("failed to forcibly update Redfish endpoint") } + } else { + log.Error().Err(err).Msgf("failed to add Redfish endpoint") } } } else {