update response status code for cluster request
(cherry picked from commit a58b5830b175860e71174c93c6f3ec1cefcd5e0d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -65,7 +65,8 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, |
| 65 | 65 |
rawVersion := r.URL.Query().Get("version")
|
| 66 | 66 |
version, err := strconv.ParseUint(rawVersion, 10, 64) |
| 67 | 67 |
if err != nil {
|
| 68 |
- return fmt.Errorf("Invalid swarm version '%s': %s", rawVersion, err.Error())
|
|
| 68 |
+ err := fmt.Errorf("invalid swarm version '%s': %v", rawVersion, err)
|
|
| 69 |
+ return errors.NewBadRequestError(err) |
|
| 69 | 70 |
} |
| 70 | 71 |
|
| 71 | 72 |
var flags types.UpdateFlags |
| ... | ... |
@@ -73,7 +74,8 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, |
| 73 | 73 |
if value := r.URL.Query().Get("rotateWorkerToken"); value != "" {
|
| 74 | 74 |
rot, err := strconv.ParseBool(value) |
| 75 | 75 |
if err != nil {
|
| 76 |
- return fmt.Errorf("invalid value for rotateWorkerToken: %s", value)
|
|
| 76 |
+ err := fmt.Errorf("invalid value for rotateWorkerToken: %s", value)
|
|
| 77 |
+ return errors.NewBadRequestError(err) |
|
| 77 | 78 |
} |
| 78 | 79 |
|
| 79 | 80 |
flags.RotateWorkerToken = rot |
| ... | ... |
@@ -82,7 +84,8 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, |
| 82 | 82 |
if value := r.URL.Query().Get("rotateManagerToken"); value != "" {
|
| 83 | 83 |
rot, err := strconv.ParseBool(value) |
| 84 | 84 |
if err != nil {
|
| 85 |
- return fmt.Errorf("invalid value for rotateManagerToken: %s", value)
|
|
| 85 |
+ err := fmt.Errorf("invalid value for rotateManagerToken: %s", value)
|
|
| 86 |
+ return errors.NewBadRequestError(err) |
|
| 86 | 87 |
} |
| 87 | 88 |
|
| 88 | 89 |
flags.RotateManagerToken = rot |
| ... | ... |
@@ -91,7 +94,7 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, |
| 91 | 91 |
if value := r.URL.Query().Get("rotateManagerUnlockKey"); value != "" {
|
| 92 | 92 |
rot, err := strconv.ParseBool(value) |
| 93 | 93 |
if err != nil {
|
| 94 |
- return fmt.Errorf("invalid value for rotateManagerUnlockKey: %s", value)
|
|
| 94 |
+ return errors.NewBadRequestError(fmt.Errorf("invalid value for rotateManagerUnlockKey: %s", value))
|
|
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
flags.RotateManagerUnlockKey = rot |
| ... | ... |
@@ -184,7 +187,8 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter, |
| 184 | 184 |
rawVersion := r.URL.Query().Get("version")
|
| 185 | 185 |
version, err := strconv.ParseUint(rawVersion, 10, 64) |
| 186 | 186 |
if err != nil {
|
| 187 |
- return fmt.Errorf("Invalid service version '%s': %s", rawVersion, err.Error())
|
|
| 187 |
+ err := fmt.Errorf("invalid service version '%s': %v", rawVersion, err)
|
|
| 188 |
+ return errors.NewBadRequestError(err) |
|
| 188 | 189 |
} |
| 189 | 190 |
|
| 190 | 191 |
// Get returns "" if the header does not exist |
| ... | ... |
@@ -294,7 +298,8 @@ func (sr *swarmRouter) updateNode(ctx context.Context, w http.ResponseWriter, r |
| 294 | 294 |
rawVersion := r.URL.Query().Get("version")
|
| 295 | 295 |
version, err := strconv.ParseUint(rawVersion, 10, 64) |
| 296 | 296 |
if err != nil {
|
| 297 |
- return fmt.Errorf("Invalid node version '%s': %s", rawVersion, err.Error())
|
|
| 297 |
+ err := fmt.Errorf("invalid node version '%s': %v", rawVersion, err)
|
|
| 298 |
+ return errors.NewBadRequestError(err) |
|
| 298 | 299 |
} |
| 299 | 300 |
|
| 300 | 301 |
if err := sr.backend.UpdateNode(vars["id"], version, node); err != nil {
|
| ... | ... |
@@ -6746,10 +6746,22 @@ paths: |
| 6746 | 6746 |
type: "array" |
| 6747 | 6747 |
items: |
| 6748 | 6748 |
$ref: "#/definitions/Node" |
| 6749 |
+ 400: |
|
| 6750 |
+ description: "bad parameter" |
|
| 6751 |
+ schema: |
|
| 6752 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6753 |
+ 404: |
|
| 6754 |
+ description: "no such node" |
|
| 6755 |
+ schema: |
|
| 6756 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6749 | 6757 |
500: |
| 6750 | 6758 |
description: "server error" |
| 6751 | 6759 |
schema: |
| 6752 | 6760 |
$ref: "#/definitions/ErrorResponse" |
| 6761 |
+ 503: |
|
| 6762 |
+ description: "node is not part of a swarm" |
|
| 6763 |
+ schema: |
|
| 6764 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6753 | 6765 |
parameters: |
| 6754 | 6766 |
- name: "filters" |
| 6755 | 6767 |
in: "query" |
| ... | ... |
@@ -6781,6 +6793,10 @@ paths: |
| 6781 | 6781 |
description: "server error" |
| 6782 | 6782 |
schema: |
| 6783 | 6783 |
$ref: "#/definitions/ErrorResponse" |
| 6784 |
+ 503: |
|
| 6785 |
+ description: "node is not part of a swarm" |
|
| 6786 |
+ schema: |
|
| 6787 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6784 | 6788 |
parameters: |
| 6785 | 6789 |
- name: "id" |
| 6786 | 6790 |
in: "path" |
| ... | ... |
@@ -6802,6 +6818,10 @@ paths: |
| 6802 | 6802 |
description: "server error" |
| 6803 | 6803 |
schema: |
| 6804 | 6804 |
$ref: "#/definitions/ErrorResponse" |
| 6805 |
+ 503: |
|
| 6806 |
+ description: "node is not part of a swarm" |
|
| 6807 |
+ schema: |
|
| 6808 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6805 | 6809 |
parameters: |
| 6806 | 6810 |
- name: "id" |
| 6807 | 6811 |
in: "path" |
| ... | ... |
@@ -6829,6 +6849,10 @@ paths: |
| 6829 | 6829 |
description: "server error" |
| 6830 | 6830 |
schema: |
| 6831 | 6831 |
$ref: "#/definitions/ErrorResponse" |
| 6832 |
+ 503: |
|
| 6833 |
+ description: "node is not part of a swarm" |
|
| 6834 |
+ schema: |
|
| 6835 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6832 | 6836 |
parameters: |
| 6833 | 6837 |
- name: "id" |
| 6834 | 6838 |
in: "path" |
| ... | ... |
@@ -6893,10 +6917,18 @@ paths: |
| 6893 | 6893 |
UpdatedAt: "2016-08-15T16:32:09.623207604Z" |
| 6894 | 6894 |
Version: |
| 6895 | 6895 |
Index: 51 |
| 6896 |
+ 404: |
|
| 6897 |
+ description: "no such swarm" |
|
| 6898 |
+ schema: |
|
| 6899 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6896 | 6900 |
500: |
| 6897 | 6901 |
description: "server error" |
| 6898 | 6902 |
schema: |
| 6899 | 6903 |
$ref: "#/definitions/ErrorResponse" |
| 6904 |
+ 503: |
|
| 6905 |
+ description: "node is not part of a swarm" |
|
| 6906 |
+ schema: |
|
| 6907 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6900 | 6908 |
tags: ["Swarm"] |
| 6901 | 6909 |
/swarm/init: |
| 6902 | 6910 |
post: |
| ... | ... |
@@ -6916,14 +6948,14 @@ paths: |
| 6916 | 6916 |
description: "bad parameter" |
| 6917 | 6917 |
schema: |
| 6918 | 6918 |
$ref: "#/definitions/ErrorResponse" |
| 6919 |
- 406: |
|
| 6920 |
- description: "node is already part of a swarm" |
|
| 6921 |
- schema: |
|
| 6922 |
- $ref: "#/definitions/ErrorResponse" |
|
| 6923 | 6919 |
500: |
| 6924 | 6920 |
description: "server error" |
| 6925 | 6921 |
schema: |
| 6926 | 6922 |
$ref: "#/definitions/ErrorResponse" |
| 6923 |
+ 503: |
|
| 6924 |
+ description: "node is already part of a swarm" |
|
| 6925 |
+ schema: |
|
| 6926 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6927 | 6927 |
parameters: |
| 6928 | 6928 |
- name: "body" |
| 6929 | 6929 |
in: "body" |
| ... | ... |
@@ -7089,6 +7121,10 @@ paths: |
| 7089 | 7089 |
description: "server error" |
| 7090 | 7090 |
schema: |
| 7091 | 7091 |
$ref: "#/definitions/ErrorResponse" |
| 7092 |
+ 503: |
|
| 7093 |
+ description: "node is not part of a swarm" |
|
| 7094 |
+ schema: |
|
| 7095 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7092 | 7096 |
tags: ["Swarm"] |
| 7093 | 7097 |
/swarm/unlock: |
| 7094 | 7098 |
post: |
| ... | ... |
@@ -7117,6 +7153,10 @@ paths: |
| 7117 | 7117 |
description: "server error" |
| 7118 | 7118 |
schema: |
| 7119 | 7119 |
$ref: "#/definitions/ErrorResponse" |
| 7120 |
+ 503: |
|
| 7121 |
+ description: "node is not part of a swarm" |
|
| 7122 |
+ schema: |
|
| 7123 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7120 | 7124 |
tags: ["Swarm"] |
| 7121 | 7125 |
/services: |
| 7122 | 7126 |
get: |
| ... | ... |
@@ -7133,6 +7173,10 @@ paths: |
| 7133 | 7133 |
description: "server error" |
| 7134 | 7134 |
schema: |
| 7135 | 7135 |
$ref: "#/definitions/ErrorResponse" |
| 7136 |
+ 503: |
|
| 7137 |
+ description: "node is not part of a swarm" |
|
| 7138 |
+ schema: |
|
| 7139 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7136 | 7140 |
parameters: |
| 7137 | 7141 |
- name: "filters" |
| 7138 | 7142 |
in: "query" |
| ... | ... |
@@ -7167,6 +7211,10 @@ paths: |
| 7167 | 7167 |
example: |
| 7168 | 7168 |
ID: "ak7w3gjqoa3kuz8xcpnyy0pvl" |
| 7169 | 7169 |
Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found" |
| 7170 |
+ 400: |
|
| 7171 |
+ description: "bad parameter" |
|
| 7172 |
+ schema: |
|
| 7173 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7170 | 7174 |
403: |
| 7171 | 7175 |
description: "network is not eligible for services" |
| 7172 | 7176 |
schema: |
| ... | ... |
@@ -7180,7 +7228,7 @@ paths: |
| 7180 | 7180 |
schema: |
| 7181 | 7181 |
$ref: "#/definitions/ErrorResponse" |
| 7182 | 7182 |
503: |
| 7183 |
- description: "server error or node is not part of a swarm" |
|
| 7183 |
+ description: "node is not part of a swarm" |
|
| 7184 | 7184 |
schema: |
| 7185 | 7185 |
$ref: "#/definitions/ErrorResponse" |
| 7186 | 7186 |
parameters: |
| ... | ... |
@@ -7262,6 +7310,10 @@ paths: |
| 7262 | 7262 |
description: "server error" |
| 7263 | 7263 |
schema: |
| 7264 | 7264 |
$ref: "#/definitions/ErrorResponse" |
| 7265 |
+ 503: |
|
| 7266 |
+ description: "node is not part of a swarm" |
|
| 7267 |
+ schema: |
|
| 7268 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7265 | 7269 |
parameters: |
| 7266 | 7270 |
- name: "id" |
| 7267 | 7271 |
in: "path" |
| ... | ... |
@@ -7283,6 +7335,10 @@ paths: |
| 7283 | 7283 |
description: "server error" |
| 7284 | 7284 |
schema: |
| 7285 | 7285 |
$ref: "#/definitions/ErrorResponse" |
| 7286 |
+ 503: |
|
| 7287 |
+ description: "node is not part of a swarm" |
|
| 7288 |
+ schema: |
|
| 7289 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7286 | 7290 |
parameters: |
| 7287 | 7291 |
- name: "id" |
| 7288 | 7292 |
in: "path" |
| ... | ... |
@@ -7301,6 +7357,10 @@ paths: |
| 7301 | 7301 |
description: "no error" |
| 7302 | 7302 |
schema: |
| 7303 | 7303 |
$ref: "#/definitions/ImageDeleteResponse" |
| 7304 |
+ 400: |
|
| 7305 |
+ description: "bad parameter" |
|
| 7306 |
+ schema: |
|
| 7307 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7304 | 7308 |
404: |
| 7305 | 7309 |
description: "no such service" |
| 7306 | 7310 |
schema: |
| ... | ... |
@@ -7309,6 +7369,10 @@ paths: |
| 7309 | 7309 |
description: "server error" |
| 7310 | 7310 |
schema: |
| 7311 | 7311 |
$ref: "#/definitions/ErrorResponse" |
| 7312 |
+ 503: |
|
| 7313 |
+ description: "node is not part of a swarm" |
|
| 7314 |
+ schema: |
|
| 7315 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7312 | 7316 |
parameters: |
| 7313 | 7317 |
- name: "id" |
| 7314 | 7318 |
in: "path" |
| ... | ... |
@@ -7397,6 +7461,10 @@ paths: |
| 7397 | 7397 |
description: "server error" |
| 7398 | 7398 |
schema: |
| 7399 | 7399 |
$ref: "#/definitions/ErrorResponse" |
| 7400 |
+ 503: |
|
| 7401 |
+ description: "node is not part of a swarm" |
|
| 7402 |
+ schema: |
|
| 7403 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7400 | 7404 |
parameters: |
| 7401 | 7405 |
- name: "id" |
| 7402 | 7406 |
in: "path" |
| ... | ... |
@@ -7566,11 +7634,14 @@ paths: |
| 7566 | 7566 |
Gateway: "10.255.0.1" |
| 7567 | 7567 |
Addresses: |
| 7568 | 7568 |
- "10.255.0.5/16" |
| 7569 |
- |
|
| 7570 | 7569 |
500: |
| 7571 | 7570 |
description: "server error" |
| 7572 | 7571 |
schema: |
| 7573 | 7572 |
$ref: "#/definitions/ErrorResponse" |
| 7573 |
+ 503: |
|
| 7574 |
+ description: "node is not part of a swarm" |
|
| 7575 |
+ schema: |
|
| 7576 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7574 | 7577 |
parameters: |
| 7575 | 7578 |
- name: "filters" |
| 7576 | 7579 |
in: "query" |
| ... | ... |
@@ -7604,6 +7675,10 @@ paths: |
| 7604 | 7604 |
description: "server error" |
| 7605 | 7605 |
schema: |
| 7606 | 7606 |
$ref: "#/definitions/ErrorResponse" |
| 7607 |
+ 503: |
|
| 7608 |
+ description: "node is not part of a swarm" |
|
| 7609 |
+ schema: |
|
| 7610 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7607 | 7611 |
parameters: |
| 7608 | 7612 |
- name: "id" |
| 7609 | 7613 |
in: "path" |
| ... | ... |
@@ -7636,6 +7711,10 @@ paths: |
| 7636 | 7636 |
description: "server error" |
| 7637 | 7637 |
schema: |
| 7638 | 7638 |
$ref: "#/definitions/ErrorResponse" |
| 7639 |
+ 503: |
|
| 7640 |
+ description: "node is not part of a swarm" |
|
| 7641 |
+ schema: |
|
| 7642 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7639 | 7643 |
parameters: |
| 7640 | 7644 |
- name: "filters" |
| 7641 | 7645 |
in: "query" |
| ... | ... |
@@ -7664,10 +7743,6 @@ paths: |
| 7664 | 7664 |
type: "string" |
| 7665 | 7665 |
example: |
| 7666 | 7666 |
ID: "ktnbjxoalbkvbvedmg1urrz8h" |
| 7667 |
- 406: |
|
| 7668 |
- description: "server error or node is not part of a swarm" |
|
| 7669 |
- schema: |
|
| 7670 |
- $ref: "#/definitions/ErrorResponse" |
|
| 7671 | 7667 |
409: |
| 7672 | 7668 |
description: "name conflicts with an existing object" |
| 7673 | 7669 |
schema: |
| ... | ... |
@@ -7676,6 +7751,10 @@ paths: |
| 7676 | 7676 |
description: "server error" |
| 7677 | 7677 |
schema: |
| 7678 | 7678 |
$ref: "#/definitions/ErrorResponse" |
| 7679 |
+ 503: |
|
| 7680 |
+ description: "node is not part of a swarm" |
|
| 7681 |
+ schema: |
|
| 7682 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7679 | 7683 |
parameters: |
| 7680 | 7684 |
- name: "body" |
| 7681 | 7685 |
in: "body" |
| ... | ... |
@@ -7712,14 +7791,14 @@ paths: |
| 7712 | 7712 |
description: "secret not found" |
| 7713 | 7713 |
schema: |
| 7714 | 7714 |
$ref: "#/definitions/ErrorResponse" |
| 7715 |
- 406: |
|
| 7716 |
- description: "node is not part of a swarm" |
|
| 7717 |
- schema: |
|
| 7718 |
- $ref: "#/definitions/ErrorResponse" |
|
| 7719 | 7715 |
500: |
| 7720 | 7716 |
description: "server error" |
| 7721 | 7717 |
schema: |
| 7722 | 7718 |
$ref: "#/definitions/ErrorResponse" |
| 7719 |
+ 503: |
|
| 7720 |
+ description: "node is not part of a swarm" |
|
| 7721 |
+ schema: |
|
| 7722 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7723 | 7723 |
parameters: |
| 7724 | 7724 |
- name: "id" |
| 7725 | 7725 |
in: "path" |
| ... | ... |
@@ -7743,6 +7822,10 @@ paths: |
| 7743 | 7743 |
description: "server error" |
| 7744 | 7744 |
schema: |
| 7745 | 7745 |
$ref: "#/definitions/ErrorResponse" |
| 7746 |
+ 503: |
|
| 7747 |
+ description: "node is not part of a swarm" |
|
| 7748 |
+ schema: |
|
| 7749 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7746 | 7750 |
parameters: |
| 7747 | 7751 |
- name: "id" |
| 7748 | 7752 |
in: "path" |
| ... | ... |
@@ -419,7 +419,7 @@ func (c *Cluster) Init(req types.InitRequest) (string, error) {
|
| 419 | 419 |
|
| 420 | 420 |
if err := validateAndSanitizeInitRequest(&req); err != nil {
|
| 421 | 421 |
c.Unlock() |
| 422 |
- return "", err |
|
| 422 |
+ return "", apierrors.NewBadRequestError(err) |
|
| 423 | 423 |
} |
| 424 | 424 |
|
| 425 | 425 |
listenHost, listenPort, err := resolveListenAddr(req.ListenAddr) |
| ... | ... |
@@ -506,7 +506,7 @@ func (c *Cluster) Join(req types.JoinRequest) error {
|
| 506 | 506 |
} |
| 507 | 507 |
if err := validateAndSanitizeJoinRequest(&req); err != nil {
|
| 508 | 508 |
c.Unlock() |
| 509 |
- return err |
|
| 509 |
+ return apierrors.NewBadRequestError(err) |
|
| 510 | 510 |
} |
| 511 | 511 |
|
| 512 | 512 |
listenHost, listenPort, err := resolveListenAddr(req.ListenAddr) |
| ... | ... |
@@ -803,7 +803,7 @@ func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlag |
| 803 | 803 |
// will be used to swarmkit. |
| 804 | 804 |
clusterSpec, err := convert.SwarmSpecToGRPC(spec) |
| 805 | 805 |
if err != nil {
|
| 806 |
- return err |
|
| 806 |
+ return apierrors.NewBadRequestError(err) |
|
| 807 | 807 |
} |
| 808 | 808 |
|
| 809 | 809 |
_, err = c.client.UpdateCluster( |
| ... | ... |
@@ -1085,7 +1085,7 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apity |
| 1085 | 1085 |
|
| 1086 | 1086 |
serviceSpec, err := convert.ServiceSpecToGRPC(s) |
| 1087 | 1087 |
if err != nil {
|
| 1088 |
- return nil, err |
|
| 1088 |
+ return nil, apierrors.NewBadRequestError(err) |
|
| 1089 | 1089 |
} |
| 1090 | 1090 |
|
| 1091 | 1091 |
ctnr := serviceSpec.Task.GetContainer() |
| ... | ... |
@@ -1168,7 +1168,7 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ |
| 1168 | 1168 |
|
| 1169 | 1169 |
serviceSpec, err := convert.ServiceSpecToGRPC(spec) |
| 1170 | 1170 |
if err != nil {
|
| 1171 |
- return nil, err |
|
| 1171 |
+ return nil, apierrors.NewBadRequestError(err) |
|
| 1172 | 1172 |
} |
| 1173 | 1173 |
|
| 1174 | 1174 |
currentService, err := getService(ctx, c.client, serviceIDOrName) |
| ... | ... |
@@ -1383,7 +1383,7 @@ func (c *Cluster) GetNodes(options apitypes.NodeListOptions) ([]types.Node, erro |
| 1383 | 1383 |
return nodes, nil |
| 1384 | 1384 |
} |
| 1385 | 1385 |
|
| 1386 |
-// GetNode returns a node based on an ID or name. |
|
| 1386 |
+// GetNode returns a node based on an ID. |
|
| 1387 | 1387 |
func (c *Cluster) GetNode(input string) (types.Node, error) {
|
| 1388 | 1388 |
c.RLock() |
| 1389 | 1389 |
defer c.RUnlock() |
| ... | ... |
@@ -1413,7 +1413,7 @@ func (c *Cluster) UpdateNode(input string, version uint64, spec types.NodeSpec) |
| 1413 | 1413 |
|
| 1414 | 1414 |
nodeSpec, err := convert.NodeSpecToGRPC(spec) |
| 1415 | 1415 |
if err != nil {
|
| 1416 |
- return err |
|
| 1416 |
+ return apierrors.NewBadRequestError(err) |
|
| 1417 | 1417 |
} |
| 1418 | 1418 |
|
| 1419 | 1419 |
ctx, cancel := c.getRequestContext() |
| ... | ... |
@@ -3,6 +3,7 @@ package cluster |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
|
| 6 |
+ "github.com/docker/docker/api/errors" |
|
| 6 | 7 |
swarmapi "github.com/docker/swarmkit/api" |
| 7 | 8 |
"golang.org/x/net/context" |
| 8 | 9 |
) |
| ... | ... |
@@ -14,7 +15,7 @@ func getSwarm(ctx context.Context, c swarmapi.ControlClient) (*swarmapi.Cluster, |
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 | 16 |
if len(rl.Clusters) == 0 {
|
| 17 |
- return nil, fmt.Errorf("swarm not found")
|
|
| 17 |
+ return nil, errors.NewRequestNotFoundError(errNoSwarm) |
|
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 | 20 |
// TODO: assume one cluster only |
| ... | ... |
@@ -38,7 +39,8 @@ func getNode(ctx context.Context, c swarmapi.ControlClient, input string) (*swar |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
if len(rl.Nodes) == 0 {
|
| 41 |
- return nil, fmt.Errorf("node %s not found", input)
|
|
| 41 |
+ err := fmt.Errorf("node %s not found", input)
|
|
| 42 |
+ return nil, errors.NewRequestNotFoundError(err) |
|
| 42 | 43 |
} |
| 43 | 44 |
|
| 44 | 45 |
if l := len(rl.Nodes); l > 1 {
|
| ... | ... |
@@ -66,7 +68,8 @@ func getService(ctx context.Context, c swarmapi.ControlClient, input string) (*s |
| 66 | 66 |
} |
| 67 | 67 |
|
| 68 | 68 |
if len(rl.Services) == 0 {
|
| 69 |
- return nil, fmt.Errorf("service %s not found", input)
|
|
| 69 |
+ err := fmt.Errorf("service %s not found", input)
|
|
| 70 |
+ return nil, errors.NewRequestNotFoundError(err) |
|
| 70 | 71 |
} |
| 71 | 72 |
|
| 72 | 73 |
if l := len(rl.Services); l > 1 {
|
| ... | ... |
@@ -95,7 +98,8 @@ func getTask(ctx context.Context, c swarmapi.ControlClient, input string) (*swar |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
if len(rl.Tasks) == 0 {
|
| 98 |
- return nil, fmt.Errorf("task %s not found", input)
|
|
| 98 |
+ err := fmt.Errorf("task %s not found", input)
|
|
| 99 |
+ return nil, errors.NewRequestNotFoundError(err) |
|
| 99 | 100 |
} |
| 100 | 101 |
|
| 101 | 102 |
if l := len(rl.Tasks); l > 1 {
|
| ... | ... |
@@ -966,7 +966,7 @@ func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
| 966 | 966 |
} |
| 967 | 967 |
status, _, err := d.SockRequest("POST", "/swarm/init", req)
|
| 968 | 968 |
c.Assert(err, checker.IsNil) |
| 969 |
- c.Assert(status, checker.Equals, http.StatusInternalServerError) |
|
| 969 |
+ c.Assert(status, checker.Equals, http.StatusBadRequest) |
|
| 970 | 970 |
|
| 971 | 971 |
req2 := swarm.JoinRequest{
|
| 972 | 972 |
ListenAddr: "0.0.0.0:2377", |
| ... | ... |
@@ -974,7 +974,7 @@ func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
| 974 | 974 |
} |
| 975 | 975 |
status, _, err = d.SockRequest("POST", "/swarm/join", req2)
|
| 976 | 976 |
c.Assert(err, checker.IsNil) |
| 977 |
- c.Assert(status, checker.Equals, http.StatusInternalServerError) |
|
| 977 |
+ c.Assert(status, checker.Equals, http.StatusBadRequest) |
|
| 978 | 978 |
} |
| 979 | 979 |
|
| 980 | 980 |
func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|