Merge "Reduce the complexity of ScreenRedfishError"

This commit is contained in:
Zuul 2020-04-01 21:31:31 +00:00 committed by Gerrit Code Review
commit 5f1eff7858

View File

@ -39,10 +39,18 @@ func (e ErrOperationRetriesExceeded) Error() string {
// ScreenRedfishError provides detailed error checking on a Redfish client response. // ScreenRedfishError provides detailed error checking on a Redfish client response.
func ScreenRedfishError(httpResp *http.Response, clientErr error) error { func ScreenRedfishError(httpResp *http.Response, clientErr error) error {
if httpResp == nil {
return ErrRedfishClient{Message: "HTTP request failed. Please try again."}
}
// NOTE(drewwalters96): clientErr may not be nil even though the request was successful. The HTTP status code // NOTE(drewwalters96): clientErr may not be nil even though the request was successful. The HTTP status code
// has to be verified for success on each request. The Redfish client uses HTTP codes 200 and 204 to indicate // has to be verified for success on each request. The Redfish client uses HTTP codes 200 and 204 to indicate
// success. // success.
if httpResp != nil && (httpResp.StatusCode < http.StatusOK || httpResp.StatusCode > http.StatusNoContent) { if httpResp.StatusCode >= http.StatusOK && httpResp.StatusCode <= http.StatusNoContent {
// This range of status codes indicate success
return nil
}
if clientErr == nil { if clientErr == nil {
return ErrRedfishClient{Message: http.StatusText(httpResp.StatusCode)} return ErrRedfishClient{Message: http.StatusText(httpResp.StatusCode)}
} }
@ -59,9 +67,4 @@ func ScreenRedfishError(httpResp *http.Response, clientErr error) error {
} }
return ErrRedfishClient{Message: resp.Error.Message} return ErrRedfishClient{Message: resp.Error.Message}
} else if httpResp == nil {
return ErrRedfishClient{Message: "HTTP request failed. Please try again."}
}
return nil
} }