Преглед изворни кода

Merge pull request #25003 from thaJeztah/make-network-error-less-DRY

make network errors less DRY
Madhu Venugopal пре 9 година
родитељ
комит
3e7d864925
1 измењених фајлова са 5 додато и 16 уклоњено
  1. 5 16
      api/server/router/network/network_routes.go

+ 5 - 16
api/server/router/network/network_routes.go

@@ -8,6 +8,7 @@ import (
 	"golang.org/x/net/context"
 
 	"github.com/docker/docker/api/server/httputils"
+	"github.com/docker/docker/errors"
 	"github.com/docker/engine-api/types"
 	"github.com/docker/engine-api/types/filters"
 	"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() {
-		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)
@@ -147,7 +149,8 @@ func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.Respon
 	}
 
 	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)
@@ -292,17 +295,3 @@ func buildEndpointResource(e libnetwork.Endpoint) types.EndpointResource {
 	}
 	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)}
-}