Return StatusNotFound when multiple volumes matching occurs

Fixes #22616

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2024-05-15 06:10:14 -04:00
parent 759e546217
commit 6408a05927
2 changed files with 11 additions and 9 deletions

View File

@ -34,23 +34,25 @@ func Error(w http.ResponseWriter, code int, err error) {
}
func VolumeNotFound(w http.ResponseWriter, name string, err error) {
if !errors.Is(err, define.ErrNoSuchVolume) {
InternalServerError(w, err)
}
if errors.Is(err, define.ErrNoSuchVolume) || errors.Is(err, define.ErrVolumeExists) {
Error(w, http.StatusNotFound, err)
return
}
InternalServerError(w, err)
}
func ContainerNotFound(w http.ResponseWriter, name string, err error) {
if errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrExists) {
Error(w, http.StatusNotFound, err)
} else {
InternalServerError(w, err)
return
}
InternalServerError(w, err)
}
func ImageNotFound(w http.ResponseWriter, name string, err error) {
if !errors.Is(err, storage.ErrImageUnknown) {
InternalServerError(w, err)
return
}
Error(w, http.StatusNotFound, err)
}
@ -58,6 +60,7 @@ func ImageNotFound(w http.ResponseWriter, name string, err error) {
func NetworkNotFound(w http.ResponseWriter, name string, err error) {
if !errors.Is(err, define.ErrNoSuchNetwork) {
InternalServerError(w, err)
return
}
Error(w, http.StatusNotFound, err)
}
@ -65,6 +68,7 @@ func NetworkNotFound(w http.ResponseWriter, name string, err error) {
func PodNotFound(w http.ResponseWriter, name string, err error) {
if !errors.Is(err, define.ErrNoSuchPod) {
InternalServerError(w, err)
return
}
Error(w, http.StatusNotFound, err)
}
@ -72,6 +76,7 @@ func PodNotFound(w http.ResponseWriter, name string, err error) {
func SessionNotFound(w http.ResponseWriter, name string, err error) {
if !errors.Is(err, define.ErrNoSuchExecSession) {
InternalServerError(w, err)
return
}
Error(w, http.StatusNotFound, err)
}
@ -79,6 +84,7 @@ func SessionNotFound(w http.ResponseWriter, name string, err error) {
func SecretNotFound(w http.ResponseWriter, nameOrID string, err error) {
if errorhandling.Cause(err).Error() != "no such secret" {
InternalServerError(w, err)
return
}
Error(w, http.StatusNotFound, err)
}

View File

@ -105,10 +105,6 @@ var _ = Describe("Podman volume rm", func() {
// boltdb issues volume name in quotes
expect = `more than one result for volume name "myv": volume already exists`
}
if IsRemote() {
// FIXME: #22616
expect = `unmarshalling error into &errorhandling.ErrorModel`
}
Expect(session).To(ExitWithError(125, expect))
session = podmanTest.Podman([]string{"volume", "ls"})