this patch makes the client return errors matching
the errdefs interface.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"net/http" |
| 6 | 6 |
"path" |
| 7 | 7 |
|
| 8 |
+ "github.com/docker/docker/api/server/httputils" |
|
| 8 | 9 |
"github.com/docker/docker/api/types" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -14,6 +15,10 @@ import ( |
| 14 | 14 |
// by the daemon. |
| 15 | 15 |
func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
| 16 | 16 |
var ping types.Ping |
| 17 |
+ |
|
| 18 |
+ // Using cli.buildRequest() + cli.doRequest() instead of cli.sendRequest() |
|
| 19 |
+ // because ping requests are used during API version negotiation, so we want |
|
| 20 |
+ // to hit the non-versioned /_ping endpoint, not /v1.xx/_ping |
|
| 17 | 21 |
req, err := cli.buildRequest("HEAD", path.Join(cli.basePath, "/_ping"), nil, nil)
|
| 18 | 22 |
if err != nil {
|
| 19 | 23 |
return ping, err |
| ... | ... |
@@ -43,7 +48,8 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
| 43 | 43 |
func parsePingResponse(cli *Client, resp serverResponse) (types.Ping, error) {
|
| 44 | 44 |
var ping types.Ping |
| 45 | 45 |
if resp.header == nil {
|
| 46 |
- return ping, cli.checkResponseErr(resp) |
|
| 46 |
+ err := cli.checkResponseErr(resp) |
|
| 47 |
+ return ping, httputils.FromStatusCode(err, resp.statusCode) |
|
| 47 | 48 |
} |
| 48 | 49 |
ping.APIVersion = resp.header.Get("API-Version")
|
| 49 | 50 |
ping.OSType = resp.header.Get("OSType")
|
| ... | ... |
@@ -53,5 +59,6 @@ func parsePingResponse(cli *Client, resp serverResponse) (types.Ping, error) {
|
| 53 | 53 |
if bv := resp.header.Get("Builder-Version"); bv != "" {
|
| 54 | 54 |
ping.BuilderVersion = types.BuilderVersion(bv) |
| 55 | 55 |
} |
| 56 |
- return ping, cli.checkResponseErr(resp) |
|
| 56 |
+ err := cli.checkResponseErr(resp) |
|
| 57 |
+ return ping, httputils.FromStatusCode(err, resp.statusCode) |
|
| 57 | 58 |
} |
| ... | ... |
@@ -13,6 +13,7 @@ import ( |
| 13 | 13 |
"os" |
| 14 | 14 |
"strings" |
| 15 | 15 |
|
| 16 |
+ "github.com/docker/docker/api/server/httputils" |
|
| 16 | 17 |
"github.com/docker/docker/api/types" |
| 17 | 18 |
"github.com/docker/docker/api/types/versions" |
| 18 | 19 |
"github.com/pkg/errors" |
| ... | ... |
@@ -120,9 +121,10 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u |
| 120 | 120 |
} |
| 121 | 121 |
resp, err := cli.doRequest(ctx, req) |
| 122 | 122 |
if err != nil {
|
| 123 |
- return resp, err |
|
| 123 |
+ return resp, httputils.FromStatusCode(err, resp.statusCode) |
|
| 124 | 124 |
} |
| 125 |
- return resp, cli.checkResponseErr(resp) |
|
| 125 |
+ err = cli.checkResponseErr(resp) |
|
| 126 |
+ return resp, httputils.FromStatusCode(err, resp.statusCode) |
|
| 126 | 127 |
} |
| 127 | 128 |
|
| 128 | 129 |
func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) {
|