mirror of https://github.com/docker/docs.git
make network errors less DRY
There's existing code to generate these kind of errors, so make the errors added in commit cc493a52a46271df82dbebea26038502b85788b9 less DRY. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 3fa9d77bf312652ae04e902a2b6e73a0b91ec007) Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
861fa09131
commit
ec241bfeaf
|
@ -8,6 +8,7 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/docker/docker/api/server/httputils"
|
"github.com/docker/docker/api/server/httputils"
|
||||||
|
"github.com/docker/docker/errors"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
"github.com/docker/engine-api/types/filters"
|
"github.com/docker/engine-api/types/filters"
|
||||||
"github.com/docker/engine-api/types/network"
|
"github.com/docker/engine-api/types/network"
|
||||||
|
@ -121,7 +122,8 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
|
||||||
}
|
}
|
||||||
|
|
||||||
if nw.Info().Dynamic() {
|
if nw.Info().Dynamic() {
|
||||||
return newNetworkForbiddenError("operation not supported for swarm scoped networks")
|
err := fmt.Errorf("operation not supported for swarm scoped networks")
|
||||||
|
return errors.NewRequestForbiddenError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.backend.ConnectContainerToNetwork(connect.Container, nw.Name(), connect.EndpointConfig)
|
return n.backend.ConnectContainerToNetwork(connect.Container, nw.Name(), connect.EndpointConfig)
|
||||||
|
@ -147,7 +149,8 @@ func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.Respon
|
||||||
}
|
}
|
||||||
|
|
||||||
if nw.Info().Dynamic() {
|
if nw.Info().Dynamic() {
|
||||||
return newNetworkForbiddenError("operation not supported for swarm scoped networks")
|
err := fmt.Errorf("operation not supported for swarm scoped networks")
|
||||||
|
return errors.NewRequestForbiddenError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.backend.DisconnectContainerFromNetwork(disconnect.Container, nw, disconnect.Force)
|
return n.backend.DisconnectContainerFromNetwork(disconnect.Container, nw, disconnect.Force)
|
||||||
|
@ -292,17 +295,3 @@ func buildEndpointResource(e libnetwork.Endpoint) types.EndpointResource {
|
||||||
}
|
}
|
||||||
return er
|
return er
|
||||||
}
|
}
|
||||||
|
|
||||||
// networkForbiddenError represents an authorization deny error
|
|
||||||
type networkForbiddenError struct {
|
|
||||||
error
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTPErrorStatusCode returns the authorization error status code (forbidden)
|
|
||||||
func (e networkForbiddenError) HTTPErrorStatusCode() int {
|
|
||||||
return http.StatusForbidden
|
|
||||||
}
|
|
||||||
|
|
||||||
func newNetworkForbiddenError(msg string) networkForbiddenError {
|
|
||||||
return networkForbiddenError{error: fmt.Errorf("%s", msg)}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue