Added response body into error messages

This commit is contained in:
David Allen 2024-08-21 16:50:24 -06:00
parent 00aaf1bf4c
commit 989ec611c6
Signed by: towk
GPG key ID: 793B2924A49B3A3F

View file

@ -40,8 +40,12 @@ func (c SmdClient) Add(data HTTPBody, headers HTTPHeader) error {
if res != nil { if res != nil {
statusOk := res.StatusCode >= 200 && res.StatusCode < 300 statusOk := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOk { if !statusOk {
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) return fmt.Errorf("returned status code %d when adding endpoint", res.StatusCode)
} }
}
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body)) fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
} }
return err return err
@ -57,8 +61,12 @@ func (c SmdClient) Update(data HTTPBody, headers HTTPHeader) error {
if res != nil { if res != nil {
statusOk := res.StatusCode >= 200 && res.StatusCode < 300 statusOk := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOk { if !statusOk {
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) return fmt.Errorf("failed to update redfish endpoint (returned %s)", res.Status)
} }
}
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body)) fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
} }
return err return err