airshipctl/pkg/remote/redfish/errors.go
Alexander Hughes 2bf3117197 [#58] Update types for golint
This patch addresses guidance from effective go [0] and golint
failures such as:

pkg/document/document.go:8:6: type name will be used as
document.DocumentFactory by other packages, and that stutters; consider
calling this Factory
pkg/remote/errors.go:9:6: type name will be used as
remote.RemoteDirectError by other packages, and that stutters; consider
calling this DirectError
pkg/remote/remote_direct.go:27:6: type name will be used as
remote.RemoteDirectClient by other packages, and that stutters; consider
calling this DirectClient
pkg/remote/redfish/errors.go:10:6: type name will be used as
redfish.RedfishClientError by other packages, and that stutters;
consider calling this ClientError
pkg/remote/redfish/redfish.go:14:6: type name will be used as
redfish.RedfishRemoteDirect by other packages, and that stutters;
consider calling this RemoteDirect

[0] https://golang.org/doc/effective_go.html#package-names

Relates-To: #58

Change-Id: I6d94da7755c8719bbcc4a77917e283074281309a
Signed-off-by: Alexander Hughes <Alexander.Hughes@pm.me>
2020-03-03 01:41:43 +00:00

41 lines
886 B
Go

package redfish
import (
"fmt"
"net/http"
aerror "opendev.org/airship/airshipctl/pkg/errors"
)
type ClientError struct {
aerror.AirshipError
}
func NewRedfishClientErrorf(format string, v ...interface{}) error {
e := &ClientError{}
e.Message = fmt.Sprintf(format, v...)
return e
}
type ErrRedfishMissingConfig struct {
What string
}
func (e ErrRedfishMissingConfig) Error() string {
return "missing configuration: " + e.What
}
// 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
}