return errors sooner

This commit is contained in:
Ryan McKinley committed 2025-01-21 11:40:01 +03:00
1 parent ac5dab220e
commit 6f007d6986
2 files changed
+17 -16

No files matched your search

+17
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"net/http"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
@@ -46,6 +48,21 @@ func (s *listConnector) Connect(ctx context.Context, name string, opts runtime.O
return nil, fmt.Errorf("missing namespace")
}
if s == nil {
return nil, &apierrors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Message: "listConnector is null??",
}}
}
if s.lister == nil {
return nil, &apierrors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Message: "lister is null??",
}}
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rsp, err := s.lister.List(ctx, ns, name)
if err != nil {
@@ -2,7 +2,6 @@ package resources
import (
"context"
"fmt"
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
"github.com/grafana/grafana/pkg/storage/unified/resource"
@@ -19,9 +18,6 @@ type ResourceListerFromSearch struct {
}
func NewResourceLister(index resource.RepositoryIndexClient) ResourceLister {
if index == nil {
return &errorLister{}
}
return &ResourceListerFromSearch{
index: index,
}
@@ -80,15 +76,3 @@ func (o *ResourceListerFromSearch) Stats(ctx context.Context, namespace, reposit
}
return stats, nil
}
type errorLister struct{}
// List implements ResourceLister.
func (e *errorLister) List(ctx context.Context, namespace string, repository string) (*provisioning.ResourceList, error) {
return nil, fmt.Errorf("missing search index")
}
// Stats implements ResourceLister.
func (e *errorLister) Stats(ctx context.Context, namespace string, repository string) (*provisioning.ResourceStats, error) {
return nil, fmt.Errorf("missing search index")
}