mirror of https://github.com/k3s-io/k3s
pkg/apiserver: minor cleanup for errToAPIStatus()
parent
0035781c50
commit
fb3c8f9452
|
@ -36,17 +36,13 @@ func errToAPIStatus(err error) *api.Status {
|
|||
case statusError:
|
||||
status := t.Status()
|
||||
if len(status.Status) == 0 {
|
||||
status.Status = api.StatusFailure
|
||||
}
|
||||
if status.Code == 0 {
|
||||
switch status.Status {
|
||||
case api.StatusSuccess:
|
||||
if status.Code == 0 {
|
||||
status.Code = http.StatusOK
|
||||
}
|
||||
case "":
|
||||
status.Status = api.StatusFailure
|
||||
fallthrough
|
||||
case api.StatusFailure:
|
||||
if status.Code == 0 {
|
||||
status.Code = http.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,16 +26,18 @@ import (
|
|||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
)
|
||||
|
||||
func Test_errToAPIStatus(t *testing.T) {
|
||||
err := errors.NewNotFound("foo", "bar")
|
||||
status := errToAPIStatus(err)
|
||||
if status.Reason != api.StatusReasonNotFound || status.Status != api.StatusFailure {
|
||||
t.Errorf("unexpected status object: %#v", status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorsToAPIStatus(t *testing.T) {
|
||||
cases := map[error]api.Status{
|
||||
errors.NewNotFound("foo", "bar"): {
|
||||
Status: api.StatusFailure,
|
||||
Code: http.StatusNotFound,
|
||||
Reason: api.StatusReasonNotFound,
|
||||
Message: "foo \"bar\" not found",
|
||||
Details: &api.StatusDetails{
|
||||
Kind: "foo",
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
errors.NewAlreadyExists("foo", "bar"): {
|
||||
Status: api.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
|
|
Loading…
Reference in New Issue