mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
API returns 500 in case network is not found instead of 404
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
"github.com/containers/podman/v2/libpod"
|
||||
"github.com/containers/podman/v2/libpod/define"
|
||||
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||
"github.com/containers/podman/v2/pkg/domain/infra/abi"
|
||||
@ -44,9 +45,7 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
name := utils.GetName(r)
|
||||
_, err = network.InspectNetwork(config, name)
|
||||
if err != nil {
|
||||
// TODO our network package does not distinguish between not finding a
|
||||
// specific network vs not being able to read it
|
||||
utils.InternalServerError(w, err)
|
||||
utils.NetworkNotFound(w, name, err)
|
||||
return
|
||||
}
|
||||
report, err := getNetworkResourceByName(name, runtime)
|
||||
@ -285,7 +284,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if !exists {
|
||||
utils.Error(w, "network not found", http.StatusNotFound, network.ErrNetworkNotFound)
|
||||
utils.Error(w, "network not found", http.StatusNotFound, define.ErrNoSuchNetwork)
|
||||
return
|
||||
}
|
||||
if err := network.RemoveNetwork(config, name); err != nil {
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/containers/podman/v2/libpod"
|
||||
"github.com/containers/podman/v2/libpod/define"
|
||||
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||
"github.com/containers/podman/v2/pkg/domain/infra/abi"
|
||||
"github.com/containers/podman/v2/pkg/network"
|
||||
"github.com/gorilla/schema"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -78,7 +78,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if reports[0].Err != nil {
|
||||
// If the network cannot be found, we return a 404.
|
||||
if errors.Cause(err) == network.ErrNetworkNotFound {
|
||||
if errors.Cause(err) == define.ErrNoSuchNetwork {
|
||||
utils.Error(w, "Something went wrong", http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
@ -104,7 +104,7 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
reports, err := ic.NetworkInspect(r.Context(), []string{name}, options)
|
||||
if err != nil {
|
||||
// If the network cannot be found, we return a 404.
|
||||
if errors.Cause(err) == network.ErrNetworkNotFound {
|
||||
if errors.Cause(err) == define.ErrNoSuchNetwork {
|
||||
utils.Error(w, "Something went wrong", http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ func VolumeNotFound(w http.ResponseWriter, name string, err error) {
|
||||
msg := fmt.Sprintf("No such volume: %s", name)
|
||||
Error(w, msg, http.StatusNotFound, err)
|
||||
}
|
||||
|
||||
func ContainerNotFound(w http.ResponseWriter, name string, err error) {
|
||||
if errors.Cause(err) != define.ErrNoSuchCtr {
|
||||
InternalServerError(w, err)
|
||||
@ -55,6 +56,14 @@ func ImageNotFound(w http.ResponseWriter, name string, err error) {
|
||||
Error(w, msg, http.StatusNotFound, err)
|
||||
}
|
||||
|
||||
func NetworkNotFound(w http.ResponseWriter, name string, err error) {
|
||||
if errors.Cause(err) != define.ErrNoSuchNetwork {
|
||||
InternalServerError(w, err)
|
||||
}
|
||||
msg := fmt.Sprintf("No such network: %s", name)
|
||||
Error(w, msg, http.StatusNotFound, err)
|
||||
}
|
||||
|
||||
func PodNotFound(w http.ResponseWriter, name string, err error) {
|
||||
if errors.Cause(err) != define.ErrNoSuchPod {
|
||||
InternalServerError(w, err)
|
||||
|
Reference in New Issue
Block a user