Dmitry Ukov c1ed28fd25 Move all error structs to common package 'errors'
Change-Id: I91e9610b27244fe5d7500575eae24647e256dab8
2019-12-01 14:14:09 +04:00

43 lines
956 B
Go

package redfish
import (
"fmt"
"net/http"
aerror "opendev.org/airship/airshipctl/pkg/errors"
)
type RedfishClientError struct {
aerror.AirshipError
}
func NewRedfishClientErrorf(format string, v ...interface{}) error {
e := &RedfishClientError{}
e.Message = fmt.Sprintf(format, v...)
return e
}
type RedfishConfigError struct {
aerror.AirshipError
}
func NewRedfishConfigErrorf(format string, v ...interface{}) error {
e := &RedfishConfigError{}
e.Message = fmt.Sprintf(format, v...)
return e
}
// Redfish client return error if response has no body.
// In this case this function further checks the
// HTTP response code.
func ScreenRedfishError(httpResp *http.Response, err error) error {
if err != nil && httpResp != nil {
if httpResp.StatusCode < 200 || httpResp.StatusCode >= 400 {
return NewRedfishClientErrorf("%s", err.Error())
}
} else if err != nil {
return NewRedfishClientErrorf("%s", err.Error())
}
return nil
}