Storage: Consolidate error handling (#91167)
This commit is contained in:
@@ -14,42 +14,12 @@ import (
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
|
||||
grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/resource"
|
||||
)
|
||||
|
||||
func errorWrap(status *resource.ErrorResult) error {
|
||||
if status != nil {
|
||||
err := &apierrors.StatusError{ErrStatus: metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: status.Code,
|
||||
Reason: metav1.StatusReason(status.Reason),
|
||||
Message: status.Message,
|
||||
}}
|
||||
if status.Details != nil {
|
||||
err.ErrStatus.Details = &metav1.StatusDetails{
|
||||
Group: status.Details.Group,
|
||||
Kind: status.Details.Kind,
|
||||
Name: status.Details.Name,
|
||||
UID: types.UID(status.Details.Uid),
|
||||
RetryAfterSeconds: status.Details.RetryAfterSeconds,
|
||||
}
|
||||
for _, c := range status.Details.Causes {
|
||||
err.ErrStatus.Details.Causes = append(err.ErrStatus.Details.Causes, metav1.StatusCause{
|
||||
Type: metav1.CauseType(c.Reason),
|
||||
Message: c.Message,
|
||||
Field: c.Field,
|
||||
})
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func toListRequest(k *resource.ResourceKey, opts storage.ListOptions) (*resource.ListRequest, storage.SelectionPredicate, error) {
|
||||
predicate := opts.Predicate
|
||||
req := &resource.ListRequest{
|
||||
|
||||
Reference in New Issue
Block a user