errors

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package errors contains useful functionality for conversion errors

Index

Constants

View Source
const (
	// StatusReasonCredentialNotProvided indicate that credential not provided
	StatusReasonCredentialNotProvided metav1.StatusReason = "CredentialNotProvided" //nolint:gosec
	// StatusReasonUnauthorized indicate that the credential provided is invalid
	StatusReasonUnauthorized metav1.StatusReason = "Unauthorized"

	// StatusReasonFileNotFound indicate that requested file not found
	StatusReasonFileNotFound metav1.StatusReason = "FileNotFound"

	// StatusReasonGitRevisionNotFound indicate that requested git revision not found
	StatusReasonGitRevisionNotFound metav1.StatusReason = "GitRevisionNotFound"

	// StatusReasonToolServiceUnavailable indicate that requested tool service unavailable
	StatusReasonToolServiceUnavailable metav1.StatusReason = "ToolServiceUnavailable"

	// StatusReasonStorageClassNotFound indicate that default storage class not found
	StatusReasonStorageClassNotFound metav1.StatusReason = "DefaultStorageClassNotFound"
)

Variables

View Source
var ErrNilPointer = errors.New("nil pointer")

ErrNilPointer indicates nil pointer, avoid panic. Although unlikely just in case

View Source
var RESTAPIGroupResource = schema.GroupResource{Group: "katanomi.dev", Resource: "API"}

RESTAPIGroupResource fake GroupResource to use errors api

View Source
var RESTClientGroupResource = schema.GroupResource{Group: "katanomi.dev", Resource: "RESTfulClient"}

RESTClientGroupResource fake GroupResource to use errors api

Functions

func AsAPIError

func AsAPIError(err error) error

AsAPIError returns an error as a apimachinary api error

func AsStatusCode

func AsStatusCode(err error) int

AsStatusCode returns the code from a errors.APIStatus, if not compatible will return InternalServerError

func AsStatusError

func AsStatusError(response *resty.Response, grs ...schema.GroupResource) error

AsStatusError transform resty response to status error

func ConvertKnativeFieldErrorToErrorList

func ConvertKnativeFieldErrorToErrorList(err *apis.FieldError) field.ErrorList

func ConvertKnativeFieldErrorToInternalError

func ConvertKnativeFieldErrorToInternalError(err *apis.FieldError) *field.Error

func ConvertResponseError added in v0.3.0

func ConvertResponseError(ctx context.Context, response *http.Response, err error, gvk schema.GroupVersionKind, names ...string) error

ConvertResponseError converts a http response and an error into a kubernetes api error ctx is the basic context, response is the response object from tool sdk, err is the returned error gvk is the GroupVersionKind object with type meta for the object names supports one optional name to be given and will be attributed as the resource name in the returned error

func ConvertToPluginK8StatusError added in v0.8.0

func ConvertToPluginK8StatusError(ctx context.Context, response *http.Response, err error, gvk schema.GroupVersionKind, names ...string) error

ConvertToPluginK8StatusError converts a http response from plugin and an error into a kubernetes api error if the error is a kubernetes api error return it directly if the error is a common error then convert it to toolServiceUnavailable or Unauthorized error ctx is the basic context, response is the response object from tool sdk, err is the returned error names supports one optional name to be given and will be attributed as the resource name in the returned error

func GVKToGVR added in v0.7.0

GVKToGVR convert schema GroupVersionKind to GroupVersionResource Warning: this function just for show error info

func HandleError

func HandleError(req *restful.Request, resp *restful.Response, err error)

HandleError handles error in requests

func IsCredentialNotProvided added in v0.8.0

func IsCredentialNotProvided(err error) bool

IsCredentialNotProvided judge if the error is CredentialNotProvided

func IsDefaultStorageClassNotFound added in v0.10.0

func IsDefaultStorageClassNotFound(err error) bool

IsDefaultStorageClassNotFound judge if the error is DefaultStorageClassNotFound

func IsFileNotFound added in v0.8.0

func IsFileNotFound(err error) bool

IsFileNotFound judge if the error is FileNotFound

func IsGitRevisionNotFound added in v0.8.0

func IsGitRevisionNotFound(err error) bool

IsGitRevisionNotFound judge if the error is GitRevisionNotFound

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError this will check against a list of know non-temporary related errors like 403-Forbidden etc all others will be considered to be temporary

func IsToolServiceUnavailable added in v0.8.0

func IsToolServiceUnavailable(err error) bool

IsToolServiceUnavailable judge if the error is ToolServiceUnavailable

func IsUnauthorized added in v0.8.0

func IsUnauthorized(err error) bool

IsUnauthorized judge if the error is Unauthorized

func NewCredentialNotProvided added in v0.8.0

func NewCredentialNotProvided(message string) error

NewCredentialNotProvided init a CredentialNotProvided k8s api error

func NewDefaultStorageClassNotFound added in v0.10.0

func NewDefaultStorageClassNotFound(message string) error

NewDefaultStorageClassNotFound init a GitRevisionNotFound k8s api error

func NewFileNotFound added in v0.8.0

func NewFileNotFound(message string) error

NewFileNotFound init a FileNotFound k8s api error

func NewGitRevisionNotFound added in v0.8.0

func NewGitRevisionNotFound(message string) error

NewGitRevisionNotFound init a GitRevisionNotFound k8s api error

func Reason added in v0.8.0

func Reason(err error) (exist bool, reason metav1.StatusReason)

Reason return reason for the error if it is a status reason error

Types

type TemporaryError

type TemporaryError interface {
	error
	Temporary() bool
}

TemporaryError is an error and has a Temporary function

Jump to

Keyboard shortcuts

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