Fixed HTTP response status code check for all successful codes

This commit is contained in:
David J. Allen 2023-10-24 08:04:14 -06:00
parent 4298912ee7
commit b85aae84c3

View file

@ -5,7 +5,6 @@ package smd
// https://github.com/alexlovelltroy/hms-smd
import (
"fmt"
"net/http"
"github.com/bikeshack/magellan/internal/util"
// hms "github.com/alexlovelltroy/hms-smd"
@ -52,7 +51,8 @@ func AddRedfishEndpoint(data []byte, headers map[string]string) error {
url := makeEndpointUrl("/Inventory/RedfishEndpoints")
res, body, err := util.MakeRequest(url, "POST", data, headers)
if res != nil {
if res.StatusCode != http.StatusOK {
statusOk := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOk {
return fmt.Errorf("could not add redfish endpoint")
}
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
@ -69,7 +69,8 @@ func UpdateRedfishEndpoint(xname string, data []byte, headers map[string]string)
res, body, err := util.MakeRequest(url, "PUT", data, headers)
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
if res != nil {
if res.StatusCode != http.StatusOK {
statusOk := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOk {
return fmt.Errorf("could not update redfish endpoint")
}
}