mirror of
https://github.com/moby/moby.git
synced 2026-07-12 02:25:19 +00:00
client/request: use containerd errdefs checks
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
7e8b26ecb9
commit
df96159df0
@@ -116,10 +116,8 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u
|
||||
|
||||
resp, err := cli.doRequest(req)
|
||||
switch {
|
||||
case errors.Is(err, context.Canceled):
|
||||
return nil, errdefs.Cancelled(err)
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
return nil, errdefs.Deadline(err)
|
||||
case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
|
||||
return nil, err
|
||||
case err == nil:
|
||||
return resp, cli.checkResponseErr(resp)
|
||||
default:
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@@ -91,7 +91,7 @@ func TestPlainTextError(t *testing.T) {
|
||||
client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
_, err := client.ContainerList(context.Background(), container.ListOptions{})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
// TestResponseErrors tests handling of error responses returned by the API.
|
||||
@@ -221,7 +221,7 @@ func TestResponseErrors(t *testing.T) {
|
||||
}
|
||||
_, err := client.Ping(context.Background())
|
||||
assert.Check(t, is.Error(err, tc.expected))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func TestInfiniteError(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := client.Ping(context.Background())
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
assert.Check(t, is.ErrorContains(err, "request returned Internal Server Error"))
|
||||
}
|
||||
|
||||
@@ -258,7 +258,6 @@ func TestCanceledContext(t *testing.T) {
|
||||
cancel()
|
||||
|
||||
_, err := client.sendRequest(ctx, http.MethodGet, testEndpoint, nil, nil, nil)
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsCancelled))
|
||||
assert.Check(t, is.ErrorIs(err, context.Canceled))
|
||||
}
|
||||
|
||||
@@ -278,6 +277,5 @@ func TestDeadlineExceededContext(t *testing.T) {
|
||||
<-ctx.Done()
|
||||
|
||||
_, err := client.sendRequest(ctx, http.MethodGet, testEndpoint, nil, nil, nil)
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsDeadline))
|
||||
assert.Check(t, is.ErrorIs(err, context.DeadlineExceeded))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user