apierror

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2020 License: Apache-2.0 Imports: 13 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	// ErrTimedOut is returned when the error is context.DeadlineExceeded.
	ErrTimedOut = errors.New("operation timed out")

	// ErrMissingElevatedPermissions is returned when the error code is 449.
	ErrMissingElevatedPermissions = errors.New("the requested operation requires elevated permissions")
)

Functions

func NewJSONError added in v1.1.0

func NewJSONError(err error) error

NewJSONError creates a marshaleable error from an error.

func Unwrap

func Unwrap(err error) error

Unwrap 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 ofmultierror.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.

Types

type JSONError added in v1.1.0

type JSONError struct {
	Message string `json:"message,omitempty"`
}

JSONError wraps any incoming error inside this struct so that it can be correctly marshaled to JSON. If Error() is called, the error is still returned in a string format.

func (JSONError) Error added in v1.1.0

func (me JSONError) Error() string

Error complies with the error interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL