Documentation ¶
Index ¶
Constants ¶
const (
// ErrTimedOutMsg is returned when the error is context.DeadlineExceeded.
ErrTimedOutMsg = "operation timed out"
)
Variables ¶
var ( // ErrMissingAPI is thrown when the *api.API reference is null. ErrMissingAPI = errors.New("api reference is required for the operation") // ErrDeploymentID is the message returned when a provided cluster id is not of the expected length (32 chars). ErrDeploymentID = errors.New("deployment id should have a length of 32 characters") // ErrMissingElevatedPermissions is returned when the error code is 449. ErrMissingElevatedPermissions = errors.New("the requested operation requires elevated permissions") )
Functions ¶
func IsRuntimeStatusCode ¶
IsRuntimeStatusCode returns true when the error is of *runtime.APIError type and the error status code matches the one passed as the argument.
func IsRuntimeStatusCodeHasString ¶
IsRuntimeStatusCodeHasString returns true when the error is *runtime.APIError and the error status code matches the one passed as the argument.
func NewJSONError ¶
NewJSONError creates a marshaleable error from an error.
func Unwrap ¶
Unwrap Deprecated: unpacks an error message returned from a client API call. It checks for a few cases where the returned API error might not have been properly casted to its error type. It covers the following cases in order:
- error is nil, in which case nil is returned.
- error is a context.DeadlineExceeded error, which equals a timeout.
- error is of type *runtime.APIError, meaning the returned API error wasn't defined in the Swagger spec from which the source code has been generated
- HTTP code is 449, the authenticated user needs to elevate-permissions.
- The type wraps *http.Response, the body is read and tries json.Unmarshal to *models.BasicFailedResponse and each of the BasicFailedReplyElement is then added to an instance of multierror.Prefixed and returned.
- The error is unknown, returns "<OperationName> (status <StatusCode)".
- error is a correctly unpacked into BasicFailedReply object which needs to be unpacked from its container struct. If the error cannot be unpacked to a BasicFailedReply, then a stringified json.MarshalIndent error is formed.
func Wrap ¶
Wrap creates a new Error from the passed error, it doesn't modify the original error, but instead, tries to unwrap and extract the wrapped errors form the go-openapi/runtime operations. The original error type can be accessed by calling Unwrap() or errors.Unwrap/Is/As.
If the error is of *models.BasicFailedReply type, then the errors are unpacked into a *multierror.Prefixed which can be obtained by calling Multierror(). The other possible case is when the API returns an error with an unexpected status code which is not present in the swagger spec, in which case, the same operation will be attempted (unwrapping a BasicFailedReply) with a fallback to unmarshal any JSON which can be read:
- error is nil, in which case nil is returned.
- error is a context.DeadlineExceeded error, which equals a timeout.
- error is of type *runtime.APIError, meaning the returned API error wasn't defined in the Swagger spec from which the source code has been generated
- HTTP code is 449, the authenticated user needs to elevate-permissions.
- The type wraps *http.Response, the body is read and tries json.Unmarshal to *models.BasicFailedResponse and each of the BasicFailedReplyElement is then added to an instance of multierror.Prefixed and returned.
- The error is unknown, returns "<OperationName> (status <StatusCode)".
Types ¶
type Error ¶
type Error struct { // Err is the unmodified wrapped error. Err error // contains filtered or unexported fields }
Error wraps a API error and implements both the Error and Unwrap interfaces.
func (*Error) Multierror ¶
func (e *Error) Multierror() *multierror.Prefixed
Multierror returns a multierror if there's one.