Signed-off-by: allencloud <allen.sun@daocloud.io>
| ... | ... |
@@ -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 {
|
| ... | ... |
@@ -6730,10 +6730,22 @@ paths: |
| 6730 | 6730 |
type: "array" |
| 6731 | 6731 |
items: |
| 6732 | 6732 |
$ref: "#/definitions/Node" |
| 6733 |
+ 400: |
|
| 6734 |
+ description: "bad parameter" |
|
| 6735 |
+ schema: |
|
| 6736 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6737 |
+ 404: |
|
| 6738 |
+ description: "no such node" |
|
| 6739 |
+ schema: |
|
| 6740 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6733 | 6741 |
500: |
| 6734 | 6742 |
description: "server error" |
| 6735 | 6743 |
schema: |
| 6736 | 6744 |
$ref: "#/definitions/ErrorResponse" |
| 6745 |
+ 503: |
|
| 6746 |
+ description: "node is not part of a swarm" |
|
| 6747 |
+ schema: |
|
| 6748 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6737 | 6749 |
parameters: |
| 6738 | 6750 |
- name: "filters" |
| 6739 | 6751 |
in: "query" |
| ... | ... |
@@ -6765,6 +6777,10 @@ paths: |
| 6765 | 6765 |
description: "server error" |
| 6766 | 6766 |
schema: |
| 6767 | 6767 |
$ref: "#/definitions/ErrorResponse" |
| 6768 |
+ 503: |
|
| 6769 |
+ description: "node is not part of a swarm" |
|
| 6770 |
+ schema: |
|
| 6771 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6768 | 6772 |
parameters: |
| 6769 | 6773 |
- name: "id" |
| 6770 | 6774 |
in: "path" |
| ... | ... |
@@ -6786,6 +6802,10 @@ paths: |
| 6786 | 6786 |
description: "server error" |
| 6787 | 6787 |
schema: |
| 6788 | 6788 |
$ref: "#/definitions/ErrorResponse" |
| 6789 |
+ 503: |
|
| 6790 |
+ description: "node is not part of a swarm" |
|
| 6791 |
+ schema: |
|
| 6792 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6789 | 6793 |
parameters: |
| 6790 | 6794 |
- name: "id" |
| 6791 | 6795 |
in: "path" |
| ... | ... |
@@ -6813,6 +6833,10 @@ paths: |
| 6813 | 6813 |
description: "server error" |
| 6814 | 6814 |
schema: |
| 6815 | 6815 |
$ref: "#/definitions/ErrorResponse" |
| 6816 |
+ 503: |
|
| 6817 |
+ description: "node is not part of a swarm" |
|
| 6818 |
+ schema: |
|
| 6819 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6816 | 6820 |
parameters: |
| 6817 | 6821 |
- name: "id" |
| 6818 | 6822 |
in: "path" |
| ... | ... |
@@ -6877,10 +6901,18 @@ paths: |
| 6877 | 6877 |
UpdatedAt: "2016-08-15T16:32:09.623207604Z" |
| 6878 | 6878 |
Version: |
| 6879 | 6879 |
Index: 51 |
| 6880 |
+ 404: |
|
| 6881 |
+ description: "no such swarm" |
|
| 6882 |
+ schema: |
|
| 6883 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6880 | 6884 |
500: |
| 6881 | 6885 |
description: "server error" |
| 6882 | 6886 |
schema: |
| 6883 | 6887 |
$ref: "#/definitions/ErrorResponse" |
| 6888 |
+ 503: |
|
| 6889 |
+ description: "node is not part of a swarm" |
|
| 6890 |
+ schema: |
|
| 6891 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6884 | 6892 |
tags: ["Swarm"] |
| 6885 | 6893 |
/swarm/init: |
| 6886 | 6894 |
post: |
| ... | ... |
@@ -6900,14 +6932,14 @@ paths: |
| 6900 | 6900 |
description: "bad parameter" |
| 6901 | 6901 |
schema: |
| 6902 | 6902 |
$ref: "#/definitions/ErrorResponse" |
| 6903 |
- 406: |
|
| 6904 |
- description: "node is already part of a swarm" |
|
| 6905 |
- schema: |
|
| 6906 |
- $ref: "#/definitions/ErrorResponse" |
|
| 6907 | 6903 |
500: |
| 6908 | 6904 |
description: "server error" |
| 6909 | 6905 |
schema: |
| 6910 | 6906 |
$ref: "#/definitions/ErrorResponse" |
| 6907 |
+ 503: |
|
| 6908 |
+ description: "node is already part of a swarm" |
|
| 6909 |
+ schema: |
|
| 6910 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 6911 | 6911 |
parameters: |
| 6912 | 6912 |
- name: "body" |
| 6913 | 6913 |
in: "body" |
| ... | ... |
@@ -7073,6 +7105,10 @@ paths: |
| 7073 | 7073 |
description: "server error" |
| 7074 | 7074 |
schema: |
| 7075 | 7075 |
$ref: "#/definitions/ErrorResponse" |
| 7076 |
+ 503: |
|
| 7077 |
+ description: "node is not part of a swarm" |
|
| 7078 |
+ schema: |
|
| 7079 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7076 | 7080 |
tags: ["Swarm"] |
| 7077 | 7081 |
/swarm/unlock: |
| 7078 | 7082 |
post: |
| ... | ... |
@@ -7101,6 +7137,10 @@ paths: |
| 7101 | 7101 |
description: "server error" |
| 7102 | 7102 |
schema: |
| 7103 | 7103 |
$ref: "#/definitions/ErrorResponse" |
| 7104 |
+ 503: |
|
| 7105 |
+ description: "node is not part of a swarm" |
|
| 7106 |
+ schema: |
|
| 7107 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7104 | 7108 |
tags: ["Swarm"] |
| 7105 | 7109 |
/services: |
| 7106 | 7110 |
get: |
| ... | ... |
@@ -7117,6 +7157,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 |
parameters: |
| 7121 | 7125 |
- name: "filters" |
| 7122 | 7126 |
in: "query" |
| ... | ... |
@@ -7151,6 +7195,10 @@ paths: |
| 7151 | 7151 |
example: |
| 7152 | 7152 |
ID: "ak7w3gjqoa3kuz8xcpnyy0pvl" |
| 7153 | 7153 |
Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found" |
| 7154 |
+ 400: |
|
| 7155 |
+ description: "bad parameter" |
|
| 7156 |
+ schema: |
|
| 7157 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7154 | 7158 |
403: |
| 7155 | 7159 |
description: "network is not eligible for services" |
| 7156 | 7160 |
schema: |
| ... | ... |
@@ -7164,7 +7212,7 @@ paths: |
| 7164 | 7164 |
schema: |
| 7165 | 7165 |
$ref: "#/definitions/ErrorResponse" |
| 7166 | 7166 |
503: |
| 7167 |
- description: "server error or node is not part of a swarm" |
|
| 7167 |
+ description: "node is not part of a swarm" |
|
| 7168 | 7168 |
schema: |
| 7169 | 7169 |
$ref: "#/definitions/ErrorResponse" |
| 7170 | 7170 |
parameters: |
| ... | ... |
@@ -7246,6 +7294,10 @@ paths: |
| 7246 | 7246 |
description: "server error" |
| 7247 | 7247 |
schema: |
| 7248 | 7248 |
$ref: "#/definitions/ErrorResponse" |
| 7249 |
+ 503: |
|
| 7250 |
+ description: "node is not part of a swarm" |
|
| 7251 |
+ schema: |
|
| 7252 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7249 | 7253 |
parameters: |
| 7250 | 7254 |
- name: "id" |
| 7251 | 7255 |
in: "path" |
| ... | ... |
@@ -7267,6 +7319,10 @@ paths: |
| 7267 | 7267 |
description: "server error" |
| 7268 | 7268 |
schema: |
| 7269 | 7269 |
$ref: "#/definitions/ErrorResponse" |
| 7270 |
+ 503: |
|
| 7271 |
+ description: "node is not part of a swarm" |
|
| 7272 |
+ schema: |
|
| 7273 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7270 | 7274 |
parameters: |
| 7271 | 7275 |
- name: "id" |
| 7272 | 7276 |
in: "path" |
| ... | ... |
@@ -7285,6 +7341,10 @@ paths: |
| 7285 | 7285 |
description: "no error" |
| 7286 | 7286 |
schema: |
| 7287 | 7287 |
$ref: "#/definitions/ImageDeleteResponse" |
| 7288 |
+ 400: |
|
| 7289 |
+ description: "bad parameter" |
|
| 7290 |
+ schema: |
|
| 7291 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7288 | 7292 |
404: |
| 7289 | 7293 |
description: "no such service" |
| 7290 | 7294 |
schema: |
| ... | ... |
@@ -7293,6 +7353,10 @@ paths: |
| 7293 | 7293 |
description: "server error" |
| 7294 | 7294 |
schema: |
| 7295 | 7295 |
$ref: "#/definitions/ErrorResponse" |
| 7296 |
+ 503: |
|
| 7297 |
+ description: "node is not part of a swarm" |
|
| 7298 |
+ schema: |
|
| 7299 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7296 | 7300 |
parameters: |
| 7297 | 7301 |
- name: "id" |
| 7298 | 7302 |
in: "path" |
| ... | ... |
@@ -7381,6 +7445,10 @@ paths: |
| 7381 | 7381 |
description: "server error" |
| 7382 | 7382 |
schema: |
| 7383 | 7383 |
$ref: "#/definitions/ErrorResponse" |
| 7384 |
+ 503: |
|
| 7385 |
+ description: "node is not part of a swarm" |
|
| 7386 |
+ schema: |
|
| 7387 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7384 | 7388 |
parameters: |
| 7385 | 7389 |
- name: "id" |
| 7386 | 7390 |
in: "path" |
| ... | ... |
@@ -7550,11 +7618,14 @@ paths: |
| 7550 | 7550 |
Gateway: "10.255.0.1" |
| 7551 | 7551 |
Addresses: |
| 7552 | 7552 |
- "10.255.0.5/16" |
| 7553 |
- |
|
| 7554 | 7553 |
500: |
| 7555 | 7554 |
description: "server error" |
| 7556 | 7555 |
schema: |
| 7557 | 7556 |
$ref: "#/definitions/ErrorResponse" |
| 7557 |
+ 503: |
|
| 7558 |
+ description: "node is not part of a swarm" |
|
| 7559 |
+ schema: |
|
| 7560 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7558 | 7561 |
parameters: |
| 7559 | 7562 |
- name: "filters" |
| 7560 | 7563 |
in: "query" |
| ... | ... |
@@ -7588,6 +7659,10 @@ paths: |
| 7588 | 7588 |
description: "server error" |
| 7589 | 7589 |
schema: |
| 7590 | 7590 |
$ref: "#/definitions/ErrorResponse" |
| 7591 |
+ 503: |
|
| 7592 |
+ description: "node is not part of a swarm" |
|
| 7593 |
+ schema: |
|
| 7594 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7591 | 7595 |
parameters: |
| 7592 | 7596 |
- name: "id" |
| 7593 | 7597 |
in: "path" |
| ... | ... |
@@ -7620,6 +7695,10 @@ paths: |
| 7620 | 7620 |
description: "server error" |
| 7621 | 7621 |
schema: |
| 7622 | 7622 |
$ref: "#/definitions/ErrorResponse" |
| 7623 |
+ 503: |
|
| 7624 |
+ description: "node is not part of a swarm" |
|
| 7625 |
+ schema: |
|
| 7626 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7623 | 7627 |
parameters: |
| 7624 | 7628 |
- name: "filters" |
| 7625 | 7629 |
in: "query" |
| ... | ... |
@@ -7648,10 +7727,6 @@ paths: |
| 7648 | 7648 |
type: "string" |
| 7649 | 7649 |
example: |
| 7650 | 7650 |
ID: "ktnbjxoalbkvbvedmg1urrz8h" |
| 7651 |
- 406: |
|
| 7652 |
- description: "server error or node is not part of a swarm" |
|
| 7653 |
- schema: |
|
| 7654 |
- $ref: "#/definitions/ErrorResponse" |
|
| 7655 | 7651 |
409: |
| 7656 | 7652 |
description: "name conflicts with an existing object" |
| 7657 | 7653 |
schema: |
| ... | ... |
@@ -7660,6 +7735,10 @@ paths: |
| 7660 | 7660 |
description: "server error" |
| 7661 | 7661 |
schema: |
| 7662 | 7662 |
$ref: "#/definitions/ErrorResponse" |
| 7663 |
+ 503: |
|
| 7664 |
+ description: "node is not part of a swarm" |
|
| 7665 |
+ schema: |
|
| 7666 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7663 | 7667 |
parameters: |
| 7664 | 7668 |
- name: "body" |
| 7665 | 7669 |
in: "body" |
| ... | ... |
@@ -7696,14 +7775,14 @@ paths: |
| 7696 | 7696 |
description: "secret not found" |
| 7697 | 7697 |
schema: |
| 7698 | 7698 |
$ref: "#/definitions/ErrorResponse" |
| 7699 |
- 406: |
|
| 7700 |
- description: "node is not part of a swarm" |
|
| 7701 |
- schema: |
|
| 7702 |
- $ref: "#/definitions/ErrorResponse" |
|
| 7703 | 7699 |
500: |
| 7704 | 7700 |
description: "server error" |
| 7705 | 7701 |
schema: |
| 7706 | 7702 |
$ref: "#/definitions/ErrorResponse" |
| 7703 |
+ 503: |
|
| 7704 |
+ description: "node is not part of a swarm" |
|
| 7705 |
+ schema: |
|
| 7706 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7707 | 7707 |
parameters: |
| 7708 | 7708 |
- name: "id" |
| 7709 | 7709 |
in: "path" |
| ... | ... |
@@ -7727,6 +7806,10 @@ paths: |
| 7727 | 7727 |
description: "server error" |
| 7728 | 7728 |
schema: |
| 7729 | 7729 |
$ref: "#/definitions/ErrorResponse" |
| 7730 |
+ 503: |
|
| 7731 |
+ description: "node is not part of a swarm" |
|
| 7732 |
+ schema: |
|
| 7733 |
+ $ref: "#/definitions/ErrorResponse" |
|
| 7730 | 7734 |
parameters: |
| 7731 | 7735 |
- name: "id" |
| 7732 | 7736 |
in: "path" |
| ... | ... |
@@ -268,7 +268,7 @@ func (c *Cluster) Init(req types.InitRequest) (string, error) {
|
| 268 | 268 |
c.mu.Unlock() |
| 269 | 269 |
|
| 270 | 270 |
if err := validateAndSanitizeInitRequest(&req); err != nil {
|
| 271 |
- return "", err |
|
| 271 |
+ return "", apierrors.NewBadRequestError(err) |
|
| 272 | 272 |
} |
| 273 | 273 |
|
| 274 | 274 |
listenHost, listenPort, err := resolveListenAddr(req.ListenAddr) |
| ... | ... |
@@ -363,7 +363,7 @@ func (c *Cluster) Join(req types.JoinRequest) error {
|
| 363 | 363 |
c.mu.Unlock() |
| 364 | 364 |
|
| 365 | 365 |
if err := validateAndSanitizeJoinRequest(&req); err != nil {
|
| 366 |
- return err |
|
| 366 |
+ return apierrors.NewBadRequestError(err) |
|
| 367 | 367 |
} |
| 368 | 368 |
|
| 369 | 369 |
listenHost, listenPort, err := resolveListenAddr(req.ListenAddr) |
| ... | ... |
@@ -628,7 +628,7 @@ func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlag |
| 628 | 628 |
// will be used to swarmkit. |
| 629 | 629 |
clusterSpec, err := convert.SwarmSpecToGRPC(spec) |
| 630 | 630 |
if err != nil {
|
| 631 |
- return err |
|
| 631 |
+ return apierrors.NewBadRequestError(err) |
|
| 632 | 632 |
} |
| 633 | 633 |
|
| 634 | 634 |
_, err = state.controlClient.UpdateCluster( |
| ... | ... |
@@ -891,7 +891,7 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apity |
| 891 | 891 |
|
| 892 | 892 |
serviceSpec, err := convert.ServiceSpecToGRPC(s) |
| 893 | 893 |
if err != nil {
|
| 894 |
- return nil, err |
|
| 894 |
+ return nil, apierrors.NewBadRequestError(err) |
|
| 895 | 895 |
} |
| 896 | 896 |
|
| 897 | 897 |
ctnr := serviceSpec.Task.GetContainer() |
| ... | ... |
@@ -976,7 +976,7 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ |
| 976 | 976 |
|
| 977 | 977 |
serviceSpec, err := convert.ServiceSpecToGRPC(spec) |
| 978 | 978 |
if err != nil {
|
| 979 |
- return nil, err |
|
| 979 |
+ return nil, apierrors.NewBadRequestError(err) |
|
| 980 | 980 |
} |
| 981 | 981 |
|
| 982 | 982 |
currentService, err := getService(ctx, state.controlClient, serviceIDOrName) |
| ... | ... |
@@ -1194,7 +1194,7 @@ func (c *Cluster) GetNodes(options apitypes.NodeListOptions) ([]types.Node, erro |
| 1194 | 1194 |
return nodes, nil |
| 1195 | 1195 |
} |
| 1196 | 1196 |
|
| 1197 |
-// GetNode returns a node based on an ID or name. |
|
| 1197 |
+// GetNode returns a node based on an ID. |
|
| 1198 | 1198 |
func (c *Cluster) GetNode(input string) (types.Node, error) {
|
| 1199 | 1199 |
c.mu.RLock() |
| 1200 | 1200 |
defer c.mu.RUnlock() |
| ... | ... |
@@ -1226,7 +1226,7 @@ func (c *Cluster) UpdateNode(input string, version uint64, spec types.NodeSpec) |
| 1226 | 1226 |
|
| 1227 | 1227 |
nodeSpec, err := convert.NodeSpecToGRPC(spec) |
| 1228 | 1228 |
if err != nil {
|
| 1229 |
- return err |
|
| 1229 |
+ return apierrors.NewBadRequestError(err) |
|
| 1230 | 1230 |
} |
| 1231 | 1231 |
|
| 1232 | 1232 |
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 {
|
| ... | ... |
@@ -962,7 +962,7 @@ func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
| 962 | 962 |
} |
| 963 | 963 |
status, _, err := d.SockRequest("POST", "/swarm/init", req)
|
| 964 | 964 |
c.Assert(err, checker.IsNil) |
| 965 |
- c.Assert(status, checker.Equals, http.StatusInternalServerError) |
|
| 965 |
+ c.Assert(status, checker.Equals, http.StatusBadRequest) |
|
| 966 | 966 |
|
| 967 | 967 |
req2 := swarm.JoinRequest{
|
| 968 | 968 |
ListenAddr: "0.0.0.0:2377", |
| ... | ... |
@@ -970,7 +970,7 @@ func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
| 970 | 970 |
} |
| 971 | 971 |
status, _, err = d.SockRequest("POST", "/swarm/join", req2)
|
| 972 | 972 |
c.Assert(err, checker.IsNil) |
| 973 |
- c.Assert(status, checker.Equals, http.StatusInternalServerError) |
|
| 973 |
+ c.Assert(status, checker.Equals, http.StatusBadRequest) |
|
| 974 | 974 |
} |
| 975 | 975 |
|
| 976 | 976 |
func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|