Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API returns 500 in case network is not found instead of 404 #7187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libpod/define/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package define

import (
"errors"

"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/pkg/network"
"github.com/containers/podman/v2/utils"
)

var (
Expand All @@ -20,6 +24,9 @@ var (
// ErrNoSuchVolume indicates the requested volume does not exist
ErrNoSuchVolume = errors.New("no such volume")

// ErrNoSuchNetwork indicates the requested network does not exist
ErrNoSuchNetwork = network.ErrNetworkNotFound

// ErrNoSuchExecSession indicates that the requested exec session does
// not exist.
ErrNoSuchExecSession = errors.New("no such exec session")
Expand Down
4 changes: 1 addition & 3 deletions pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/handlers/utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions test/apiv2/35-networks.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- sh -*-
#
# network-related tests
#

t GET /networks/non-existing-network 404

# vim: filetype=sh