rename HTTP error

This commit is contained in:
Yann Hamon 2020-11-08 16:21:48 +01:00
parent 230528102e
commit 45040c3fe2
4 changed files with 10 additions and 12 deletions

View file

@ -26,7 +26,7 @@ func downloadSchema(registries []registry.Registry, kind, version, k8sVersion st
} }
// If we get a 404, we try the next registry, but we exit if we get a real failure // If we get a 404, we try the next registry, but we exit if we get a real failure
if er, retryable := err.(registry.Retryable); retryable && !er.IsRetryable() { if _, notfound := err.(*registry.NotFoundError); notfound {
continue continue
} }

View file

@ -12,16 +12,14 @@ type KubernetesRegistry struct {
strict bool strict bool
} }
type downloadError struct { type NotFoundError struct {
err error err error
isRetryable bool
} }
func newDownloadError(err error, isRetryable bool) *downloadError { func newNetFoundError(err error) *NotFoundError {
return &downloadError{err, isRetryable} return &NotFoundError{err}
} }
func (e *downloadError) IsRetryable() bool { return e.isRetryable } func (e *NotFoundError) Error() string { return e.err.Error() }
func (e *downloadError) Error() string { return e.err.Error() }
func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *KubernetesRegistry { func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *KubernetesRegistry {
if skipTLS { if skipTLS {
@ -47,7 +45,7 @@ func (r KubernetesRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8s
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound { if resp.StatusCode == http.StatusNotFound {
return nil, newDownloadError(fmt.Errorf("no schema found"), false) return nil, newNetFoundError(fmt.Errorf("no schema found"))
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {

View file

@ -19,8 +19,8 @@ type fileNotFoundError struct {
func newFileNotFoundError(err error, isRetryable bool) *fileNotFoundError { func newFileNotFoundError(err error, isRetryable bool) *fileNotFoundError {
return &fileNotFoundError{err, isRetryable} return &fileNotFoundError{err, isRetryable}
} }
func (e *fileNotFoundError) IsRetryable() bool { return e.isRetryable } func (e *fileNotFoundError) IsNotFound() bool { return e.isRetryable }
func (e *fileNotFoundError) Error() string { return e.err.Error() } func (e *fileNotFoundError) Error() string { return e.err.Error() }
// NewLocalSchemas creates a new "registry", that will serve schemas from files, given a list of schema filenames // NewLocalSchemas creates a new "registry", that will serve schemas from files, given a list of schema filenames
func newLocalRegistry(pathTemplate string, strict bool) *LocalRegistry { func newLocalRegistry(pathTemplate string, strict bool) *LocalRegistry {

View file

@ -17,7 +17,7 @@ type Registry interface {
// Retryable indicates whether an error is a temporary or a permanent failure // Retryable indicates whether an error is a temporary or a permanent failure
type Retryable interface { type Retryable interface {
IsRetryable() bool IsNotFound() bool
} }
func schemaPath(tpl, resourceKind, resourceAPIVersion, k8sVersion string, strict bool) (string, error) { func schemaPath(tpl, resourceKind, resourceAPIVersion, k8sVersion string, strict bool) (string, error) {