Documentation ¶
Index ¶
- Constants
- func FromObject(obj interface{}) error
- func FromResponse(resp *http.Response) (err error, hasError bool)
- func HasStatusCause(err error, name CauseType) bool
- func IsAlreadyExists(err error) bool
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsInternalError(err error) bool
- func IsInvalid(err error) bool
- func IsMethodNotSupported(err error) bool
- func IsNotAcceptable(err error) bool
- func IsNotFound(err error) bool
- func IsRequestEntityTooLargeError(err error) bool
- func IsServerTimeout(err error) bool
- func IsServiceUnavailable(err error) bool
- func IsTimeout(err error) bool
- func IsTooManyRequests(err error) bool
- func IsUnauthorized(err error) bool
- func IsUnexpectedObjectError(err error) bool
- func IsUnexpectedServerError(err error) bool
- func IsUnsupportedMediaType(err error) bool
- func SuggestsClientDelay(err error) (int, bool)
- type APIStatus
- type CauseType
- type Status
- type StatusCause
- type StatusDetails
- type StatusError
- func NewAlreadyExists(name string, uid string) *StatusError
- func NewBadRequest(reason string) *StatusError
- func NewConflict(name string, err error) *StatusError
- func NewForbidden(name string, err error) *StatusError
- func NewGenericServerResponse(code int, verb string, name, serverMessage string, retryAfterSeconds int, ...) *StatusError
- func NewInternalError(err error) *StatusError
- func NewInvalid(name string, errs field.ErrorList) *StatusError
- func NewMethodNotSupported(action string) *StatusError
- func NewNotFound(name string, uid string) *StatusError
- func NewRequestEntityTooLargeError(message string) *StatusError
- func NewServerTimeout(operation string, retryAfterSeconds int) *StatusError
- func NewServiceUnavailable(reason string) *StatusError
- func NewTimeoutError(message string, retryAfterSeconds int) *StatusError
- func NewTooManyRequests(message string, retryAfterSeconds int) *StatusError
- func NewTooManyRequestsError(message string) *StatusError
- func NewUnauthorized(reason string) *StatusError
- type StatusReason
- type UnexpectedObjectError
Constants ¶
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 ¶
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 ¶
HasStatusCause returns true if the provided error has a details cause with the provided type name.
func IsAlreadyExists ¶
IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists. It supports wrapped errors.
func IsBadRequest ¶
IsBadRequest determines if err is an error which indicates that the request is invalid. It supports wrapped errors.
func IsConflict ¶
IsConflict determines if the err is an error which indicates the provided update conflicts. It supports wrapped errors.
func IsForbidden ¶
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 ¶
IsInternalError determines if err is an error which indicates an internal server error. It supports wrapped errors.
func IsInvalid ¶
IsInvalid determines if the err is an error which indicates the provided resource is not valid. It supports wrapped errors.
func IsMethodNotSupported ¶
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 ¶
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 ¶
IsNotFound returns true if the specified error was created by NewNotFound. It supports wrapped errors.
func IsRequestEntityTooLargeError ¶
IsRequestEntityTooLargeError determines if err is an error which indicates the request entity is too large. It supports wrapped errors.
func IsServerTimeout ¶
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 ¶
IsServiceUnavailable is true if the error indicates the underlying service is no longer available. It supports wrapped errors.
func IsTimeout ¶
IsTimeout determines if err is an error which indicates that request times out due to long processing. It supports wrapped errors.
func IsTooManyRequests ¶
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 ¶
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 ¶
IsUnexpectedObjectError determines if err is due to an unexpected object from the master. It supports wrapped errors.
func IsUnexpectedServerError ¶
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 ¶
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 ¶
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 ¶
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 = "" // 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" // 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'.