client: return rich / errdefs errors
this patch makes the client return errors matching the errdefs interface. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
5d8ece522b
commit
38e6d474af
2 changed files with 13 additions and 4 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
|
@ -14,6 +15,10 @@ import (
|
|||
// by the daemon.
|
||||
func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
||||
var ping types.Ping
|
||||
|
||||
// Using cli.buildRequest() + cli.doRequest() instead of cli.sendRequest()
|
||||
// because ping requests are used during API version negotiation, so we want
|
||||
// to hit the non-versioned /_ping endpoint, not /v1.xx/_ping
|
||||
req, err := cli.buildRequest("HEAD", path.Join(cli.basePath, "/_ping"), nil, nil)
|
||||
if err != nil {
|
||||
return ping, err
|
||||
|
@ -43,7 +48,8 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
|||
func parsePingResponse(cli *Client, resp serverResponse) (types.Ping, error) {
|
||||
var ping types.Ping
|
||||
if resp.header == nil {
|
||||
return ping, cli.checkResponseErr(resp)
|
||||
err := cli.checkResponseErr(resp)
|
||||
return ping, httputils.FromStatusCode(err, resp.statusCode)
|
||||
}
|
||||
ping.APIVersion = resp.header.Get("API-Version")
|
||||
ping.OSType = resp.header.Get("OSType")
|
||||
|
@ -53,5 +59,6 @@ func parsePingResponse(cli *Client, resp serverResponse) (types.Ping, error) {
|
|||
if bv := resp.header.Get("Builder-Version"); bv != "" {
|
||||
ping.BuilderVersion = types.BuilderVersion(bv)
|
||||
}
|
||||
return ping, cli.checkResponseErr(resp)
|
||||
err := cli.checkResponseErr(resp)
|
||||
return ping, httputils.FromStatusCode(err, resp.statusCode)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -120,9 +121,10 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u
|
|||
}
|
||||
resp, err := cli.doRequest(ctx, req)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return resp, httputils.FromStatusCode(err, resp.statusCode)
|
||||
}
|
||||
return resp, cli.checkResponseErr(resp)
|
||||
err = cli.checkResponseErr(resp)
|
||||
return resp, httputils.FromStatusCode(err, resp.statusCode)
|
||||
}
|
||||
|
||||
func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) {
|
||||
|
|
Loading…
Reference in a new issue