From 989ec611c634bf1c87b3a469c0ef7acc872d9806 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 16:50:24 -0600 Subject: [PATCH] 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)) }