mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
chore: use NotFound error for missing components
In this way, the return status could be 404 instead of 500
This commit is contained in:
parent
c5c19a6487
commit
bde75d6020
@ -18,7 +18,6 @@ package componentstatus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
@ -26,6 +25,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@ -136,7 +136,7 @@ func (rs *REST) Get(ctx context.Context, name string, options *metav1.GetOptions
|
||||
servers := rs.GetServersToValidate()
|
||||
|
||||
if server, ok := servers[name]; !ok {
|
||||
return nil, fmt.Errorf("Component not found: %s", name)
|
||||
return nil, apierrors.NewNotFound(api.Resource("componentstatus"), name)
|
||||
} else {
|
||||
return rs.getComponentStatus(name, server), nil
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func TestGet_BadName(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error, but did not get one")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "Component not found: invalidname") {
|
||||
if !strings.Contains(err.Error(), `componentstatus "invalidname" not found`) {
|
||||
t.Fatalf("Got unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user