errors

package
v0.0.0-...-ab02cff Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess = "Success"
	StatusFailure = "Failure"
)

Values of Status.Status

Variables

This section is empty.

Functions

func FromObject

func FromObject(obj interface{}) error

FromObject generates an StatusError from an Status, if that is the type of obj; otherwise, returns an UnexpectedObjectError.

func FromResponse

func FromResponse(resp *http.Response) (err error, hasError bool)

FromResponse determines if the http.Response contains an error, if so, it attempts to decode the error into a Status struct. If the decoding fails, an internal error is returned

func HasStatusCause

func HasStatusCause(err error, name CauseType) bool

HasStatusCause returns true if the provided error has a details cause with the provided type name.

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists. It supports wrapped errors.

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest determines if err is an error which indicates that the request is invalid. It supports wrapped errors.

func IsConflict

func IsConflict(err error) bool

IsConflict determines if the err is an error which indicates the provided update conflicts. It supports wrapped errors.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden determines if err is an error which indicates that the request is forbidden and cannot be completed as requested. It supports wrapped errors.

func IsInternalError

func IsInternalError(err error) bool

IsInternalError determines if err is an error which indicates an internal server error. It supports wrapped errors.

func IsInvalid

func IsInvalid(err error) bool

IsInvalid determines if the err is an error which indicates the provided resource is not valid. It supports wrapped errors.

func IsMethodNotSupported

func IsMethodNotSupported(err error) bool

IsMethodNotSupported determines if the err is an error which indicates the provided action could not be performed because it is not supported by the server. It supports wrapped errors.

func IsNotAcceptable

func IsNotAcceptable(err error) bool

IsNotAcceptable determines if err is an error which indicates that the request failed due to an invalid Accept header It supports wrapped errors.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the specified error was created by NewNotFound. It supports wrapped errors.

func IsRequestEntityTooLargeError

func IsRequestEntityTooLargeError(err error) bool

IsRequestEntityTooLargeError determines if err is an error which indicates the request entity is too large. It supports wrapped errors.

func IsServerTimeout

func IsServerTimeout(err error) bool

IsServerTimeout determines if err is an error which indicates that the request needs to be retried by the client. It supports wrapped errors.

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

IsServiceUnavailable is true if the error indicates the underlying service is no longer available. It supports wrapped errors.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout determines if err is an error which indicates that request times out due to long processing. It supports wrapped errors.

func IsTooManyRequests

func IsTooManyRequests(err error) bool

IsTooManyRequests determines if err is an error which indicates that there are too many requests that the server cannot handle. It supports wrapped errors.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized determines if err is an error which indicates that the request is unauthorized and requires authentication by the user. It supports wrapped errors.

func IsUnexpectedObjectError

func IsUnexpectedObjectError(err error) bool

IsUnexpectedObjectError determines if err is due to an unexpected object from the master. It supports wrapped errors.

func IsUnexpectedServerError

func IsUnexpectedServerError(err error) bool

IsUnexpectedServerError returns true if the server response was not in the expected API format, and may be the result of another HTTP actor. It supports wrapped errors.

func IsUnsupportedMediaType

func IsUnsupportedMediaType(err error) bool

IsUnsupportedMediaType determines if err is an error which indicates that the request failed due to an invalid Content-Type header It supports wrapped errors.

func SuggestsClientDelay

func SuggestsClientDelay(err error) (int, bool)

SuggestsClientDelay returns true if this error suggests a client delay as well as the suggested seconds to wait, or false if the error does not imply a wait. It does not address whether the error *should* be retried, since some errors (like a 3xx) may request delay without retry. It supports wrapped errors.

Types

type APIStatus

type APIStatus interface {
	Status() Status
}

APIStatus is exposed by errors that can be converted to an api.Status object for finer grained details.

type CauseType

type CauseType string

CauseType is a machine readable value providing more detail about what occurred in a status response. An operation may have multiple causes for a status (whether Failure or Success).

const (
	// CauseTypeFieldValueNotFound is used to report failure to find a requested value
	// (e.g. looking up an ID).
	CauseTypeFieldValueNotFound CauseType = "FieldValueNotFound"
	// CauseTypeFieldValueRequired is used to report required values that are not
	// provided (e.g. empty strings, null values, or empty arrays).
	CauseTypeFieldValueRequired CauseType = "FieldValueRequired"
	// CauseTypeFieldValueDuplicate is used to report collisions of values that must be
	// unique (e.g. unique IDs).
	CauseTypeFieldValueDuplicate CauseType = "FieldValueDuplicate"
	// CauseTypeFieldValueInvalid is used to report malformed values (e.g. failed regex
	// match).
	CauseTypeFieldValueInvalid CauseType = "FieldValueInvalid"
	// CauseTypeFieldValueNotSupported is used to report valid (as per formatting rules)
	// values that can not be handled (e.g. an enumerated string).
	CauseTypeFieldValueNotSupported CauseType = "FieldValueNotSupported"
	// CauseTypeUnexpectedServerResponse is used to report when the server responded to the client
	// without the expected return type. The presence of this cause indicates the error may be
	// due to an intervening proxy or the server software malfunctioning.
	CauseTypeUnexpectedServerResponse CauseType = "UnexpectedServerResponse"
	// FieldManagerConflict is used to report when another client claims to manage this field,
	// It should only be returned for a request using server-side apply.
	CauseTypeFieldManagerConflict CauseType = "FieldManagerConflict"
	// CauseTypeResourceVersionTooLarge is used to report that the requested resource version
	// is newer than the data observed by the API server, so the request cannot be served.
	CauseTypeResourceVersionTooLarge CauseType = "ResourceVersionTooLarge"
)

type Status

type Status struct {
	// Status of the operation.
	// One of: "Success" or "Failure".
	// +optional
	Status string `json:"status,omitempty"`
	// A human-readable description of the status of this operation.
	// +optional
	Message string `json:"message,omitempty"`
	// A machine-readable description of why this operation is in the
	// "Failure" status. If this value is empty there
	// is no information available. A Reason clarifies an HTTP status
	// code but does not override it.
	// +optional
	Reason StatusReason `json:"reason,omitempty"`
	// Extended data associated with the reason.  Each reason may define its
	// own extended details. This field is optional and the data returned
	// is not guaranteed to conform to any schema except that defined by
	// the reason type.
	// +optional
	Details *StatusDetails `json:"details,omitempty"`
	// Suggested HTTP return code for this status, 0 if not set.
	// +optional
	Code int32 `json:"code,omitempty"`
}

Status is a return value for calls that don't return other objects.

func ErrorToAPIStatus

func ErrorToAPIStatus(err error) *Status

ErrorToAPIStatus converts an error to an Status object.

type StatusCause

type StatusCause struct {
	// A machine-readable description of the cause of the error. If this value is
	// empty there is no information available.
	// +optional
	Type CauseType `json:"reason,omitempty" protobuf:"bytes,1,opt,name=reason,casttype=CauseType"`
	// A human-readable description of the cause of the error.  This field may be
	// presented as-is to a reader.
	// +optional
	Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
	// The field of the resource that has caused this error, as named by its JSON
	// serialization. May include dot and postfix notation for nested attributes.
	// Arrays are zero-indexed.  Fields may appear more than once in an array of
	// causes due to fields having multiple errors.
	// Optional.
	//
	// Examples:
	//   "name" - the field "name" on the current resource
	//   "items[0].name" - the field "name" on the first array entry in "items"
	// +optional
	Field string `json:"field,omitempty" protobuf:"bytes,3,opt,name=field"`
}

StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.

func GetStatusCause

func GetStatusCause(err error, name CauseType) (StatusCause, bool)

StatusCause returns the named cause from the provided error if it exists and the error is of the type APIStatus. Otherwise it returns false.

type StatusDetails

type StatusDetails struct {
	// The name attribute of the resource associated with the status StatusReason
	// (when there is a single name which can be described).
	// +optional
	Name string `json:"name,omitempty"`
	// UID of the resource.
	// (when there is a single resource which can be described).
	UID string `json:"uid,omitempty"`
	// The Causes array includes more details associated with the StatusReason
	// failure. Not all StatusReasons may provide detailed causes.
	// +optional
	Causes []StatusCause `json:"causes,omitempty"`
	// If specified, the time in seconds before the operation should be retried. Some errors may indicate
	// the client must take an alternate action - for those errors this field may indicate how long to wait
	// before taking the alternate action.
	// +optional
	RetryAfterSeconds int32 `json:"retryAfterSeconds,omitempty"`
}

StatusDetails is a set of additional properties that MAY be set by the server to provide additional information about a response. The Reason field of a Status object defines what attributes will be set. Clients must ignore fields that do not match the defined type of each attribute, and should assume that any attribute may be empty, invalid, or under defined.

type StatusError

type StatusError struct {
	ErrStatus Status
}

StatusError is an error intended for consumption by a REST API server; it can also be reconstructed by clients from a REST response. Public to allow easy type switches.

func NewAlreadyExists

func NewAlreadyExists(name string, uid string) *StatusError

NewAlreadyExists returns an error indicating the item requested exists by that identifier.

func NewBadRequest

func NewBadRequest(reason string) *StatusError

NewBadRequest creates an error that indicates that the request is invalid and can not be processed.

func NewConflict

func NewConflict(name string, err error) *StatusError

NewConflict returns an error indicating the item can't be updated as provided.

func NewForbidden

func NewForbidden(name string, err error) *StatusError

NewForbidden returns an error indicating the requested action was forbidden

func NewGenericServerResponse

func NewGenericServerResponse(code int, verb string, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) *StatusError

NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.

func NewInternalError

func NewInternalError(err error) *StatusError

NewInternalError returns an error indicating the item is invalid and cannot be processed.

func NewInvalid

func NewInvalid(name string, errs field.ErrorList) *StatusError

NewInvalid returns an error indicating the item is invalid and cannot be processed.

func NewMethodNotSupported

func NewMethodNotSupported(action string) *StatusError

NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.

func NewNotFound

func NewNotFound(name string, uid string) *StatusError

NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.

func NewRequestEntityTooLargeError

func NewRequestEntityTooLargeError(message string) *StatusError

NewRequestEntityTooLargeError returns an error indicating that the request entity was too large.

func NewServerTimeout

func NewServerTimeout(operation string, retryAfterSeconds int) *StatusError

NewServerTimeout returns an error indicating the requested action could not be completed due to a transient error, and the client should try again.

func NewServiceUnavailable

func NewServiceUnavailable(reason string) *StatusError

NewServiceUnavailable creates an error that indicates that the requested service is unavailable.

func NewTimeoutError

func NewTimeoutError(message string, retryAfterSeconds int) *StatusError

NewTimeoutError returns an error indicating that a timeout occurred before the request could be completed. Clients may retry, but the operation may still complete.

func NewTooManyRequests

func NewTooManyRequests(message string, retryAfterSeconds int) *StatusError

NewTooManyRequests creates an error that indicates that the client must try again later because the specified endpoint is not accepting requests. More specific details should be provided if client should know why the failure was limited4.

func NewTooManyRequestsError

func NewTooManyRequestsError(message string) *StatusError

NewTooManyRequestsError returns an error indicating that the request was rejected because the server has received too many requests. Client should wait and retry. But if the request is perishable, then the client should not retry the request.

func NewUnauthorized

func NewUnauthorized(reason string) *StatusError

NewUnauthorized returns an error indicating the client is not authorized to perform the requested action.

func (*StatusError) DebugError

func (e *StatusError) DebugError() (string, []interface{})

DebugError reports extended info about the error to debug output.

func (*StatusError) Error

func (e *StatusError) Error() string

Error implements the Error interface.

func (*StatusError) Status

func (e *StatusError) Status() Status

Status allows access to e's status without having to know the detailed workings of StatusError.

type StatusReason

type StatusReason string

StatusReason is an enumeration of possible failure causes. Each StatusReason must map to a single HTTP status code, but multiple reasons may map to the same HTTP status code.

const (
	// StatusReasonUnknown means the server has declined to indicate a specific reason.
	// The details field may contain other information about this error.
	// Status code 500.
	StatusReasonUnknown StatusReason = ""

	// StatusReasonUnauthorized means the server can be reached and understood the request, but requires
	// the user to present appropriate authorization credentials (identified by the WWW-Authenticate header)
	// in order for the action to be completed. If the user has specified credentials on the request, the
	// server considers them insufficient.
	// Status code 401
	StatusReasonUnauthorized StatusReason = "Unauthorized"

	// StatusReasonForbidden means the server can be reached and understood the request, but refuses
	// to take any further action.  It is the result of the server being configured to deny access for some reason
	// to the requested resource by the client.
	// Details (optional):
	//   "kind" string - the kind attribute of the forbidden resource
	//                   on some operations may differ from the requested
	//                   resource.
	//   "id"   string - the identifier of the forbidden resource
	// Status code 403
	StatusReasonForbidden StatusReason = "Forbidden"

	// StatusReasonNotFound means one or more resources required for this operation
	// could not be found.
	// Status code 404
	StatusReasonNotFound StatusReason = "NotFound"

	// StatusReasonAlreadyExists means the resource you are creating already exists.
	// Status code 409
	StatusReasonAlreadyExists StatusReason = "AlreadyExists"

	// StatusReasonConflict means the requested operation cannot be completed
	// due to a conflict in the operation. The client may need to alter the
	// request. Each resource may define custom details that indicate the
	// nature of the conflict.
	// Status code 409
	StatusReasonConflict StatusReason = "Conflict"

	// StatusReasonInvalid means the requested create or update operation cannot be
	// completed due to invalid data provided as part of the request. The client may
	// need to alter the request. When set, the client may use the StatusDetails
	// message field as a summary of the issues encountered.
	// Details (optional):
	//   "causes"      - one or more StatusCause entries indicating the data in the
	//                   provided resource that was invalid.  The code, message, and
	//                   field attributes will be set.
	// Status code 422
	StatusReasonInvalid StatusReason = "Invalid"

	// StatusReasonServerTimeout means the server can be reached and understood the request,
	// but cannot complete the action in a reasonable time. The client should retry the request.
	// This is may be due to temporary server load or a transient communication issue with
	// another server. Status code 500 is used because the HTTP spec provides no suitable
	// server-requested client retry and the 5xx class represents actionable errors.
	// Details (optional):
	//   "id"   string - the operation that is being attempted.
	//   "retryAfterSeconds" int32 - the number of seconds before the operation should be retried
	// Status code 500
	StatusReasonServerTimeout StatusReason = "ServerTimeout"

	// StatusReasonTimeout means that the request could not be completed within the given time.
	// Clients can get this response only when they specified a timeout param in the request,
	// or if the server cannot complete the operation within a reasonable amount of time.
	// The request might succeed with an increased value of timeout param. The client *should*
	// wait at least the number of seconds specified by the retryAfterSeconds field.
	// Details (optional):
	//   "retryAfterSeconds" int32 - the number of seconds before the operation should be retried
	// Status code 504
	StatusReasonTimeout StatusReason = "Timeout"

	// StatusReasonTooManyRequests means the server experienced too many requests within a
	// given window and that the client must wait to perform the action again. A client may
	// always retry the request that led to this error, although the client should wait at least
	// the number of seconds specified by the retryAfterSeconds field.
	// Details (optional):
	//   "retryAfterSeconds" int32 - the number of seconds before the operation should be retried
	// Status code 429
	StatusReasonTooManyRequests StatusReason = "TooManyRequests"

	// StatusReasonBadRequest means that the request itself was invalid, because the request
	// doesn't make any sense, for example deleting a read-only object.  This is different than
	// StatusReasonInvalid above which indicates that the API call could possibly succeed, but the
	// data was invalid.  API calls that return BadRequest can never succeed.
	// Status code 400
	StatusReasonBadRequest StatusReason = "BadRequest"

	// StatusReasonMethodNotAllowed means that the action the client attempted to perform on the
	// resource was not supported by the code - for instance, attempting to delete a resource that
	// can only be created. API calls that return MethodNotAllowed can never succeed.
	// Status code 405
	StatusReasonMethodNotAllowed StatusReason = "MethodNotAllowed"

	// StatusReasonNotAcceptable means that the accept types indicated by the client were not acceptable
	// to the server - for instance, attempting to receive protobuf for a resource that supports only json and yaml.
	// API calls that return NotAcceptable can never succeed.
	// Status code 406
	StatusReasonNotAcceptable StatusReason = "NotAcceptable"

	// StatusReasonRequestEntityTooLarge means that the request entity is too large.
	// Status code 413
	StatusReasonRequestEntityTooLarge StatusReason = "RequestEntityTooLarge"

	// StatusReasonUnsupportedMediaType means that the content type sent by the client is not acceptable
	// to the server - for instance, attempting to send protobuf for a resource that supports only json and yaml.
	// API calls that return UnsupportedMediaType can never succeed.
	// Status code 415
	StatusReasonUnsupportedMediaType StatusReason = "UnsupportedMediaType"

	// StatusReasonInternalError indicates that an internal error occurred, it is unexpected
	// and the outcome of the call is unknown.
	// Details (optional):
	//   "causes" - The original error
	// Status code 500
	StatusReasonInternalError StatusReason = "InternalError"

	// StatusReasonServiceUnavailable means that the request itself was valid,
	// but the requested service is unavailable at this time.
	// Retrying the request after some time might succeed.
	// Status code 503
	StatusReasonServiceUnavailable StatusReason = "ServiceUnavailable"
)

func ReasonForError

func ReasonForError(err error) StatusReason

ReasonForError returns the HTTP status for a particular error. It supports wrapped errors.

type UnexpectedObjectError

type UnexpectedObjectError struct {
	Object interface{}
}

UnexpectedObjectError can be returned by FromObject if it's passed a non-status object.

func (*UnexpectedObjectError) Error

func (u *UnexpectedObjectError) Error() string

Error returns an error message describing 'u'.

Jump to

Keyboard shortcuts

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