Browse code

client/request: use containerd errdefs checks

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2025/05/19 21:14:14
Showing 2 changed files
... ...
@@ -116,10 +116,8 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u
116 116
 
117 117
 	resp, err := cli.doRequest(req)
118 118
 	switch {
119
-	case errors.Is(err, context.Canceled):
120
-		return nil, errdefs.Cancelled(err)
121
-	case errors.Is(err, context.DeadlineExceeded):
122
-		return nil, errdefs.Deadline(err)
119
+	case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
120
+		return nil, err
123 121
 	case err == nil:
124 122
 		return resp, cli.checkResponseErr(resp)
125 123
 	default:
... ...
@@ -12,9 +12,9 @@ import (
12 12
 	"testing"
13 13
 	"time"
14 14
 
15
+	cerrdefs "github.com/containerd/errdefs"
15 16
 	"github.com/docker/docker/api/types"
16 17
 	"github.com/docker/docker/api/types/container"
17
-	"github.com/docker/docker/errdefs"
18 18
 	"gotest.tools/v3/assert"
19 19
 	is "gotest.tools/v3/assert/cmp"
20 20
 )
... ...
@@ -91,7 +91,7 @@ func TestPlainTextError(t *testing.T) {
91 91
 		client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")),
92 92
 	}
93 93
 	_, err := client.ContainerList(context.Background(), container.ListOptions{})
94
-	assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
94
+	assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
95 95
 }
96 96
 
97 97
 // TestResponseErrors tests handling of error responses returned by the API.
... ...
@@ -221,7 +221,7 @@ func TestResponseErrors(t *testing.T) {
221 221
 			}
222 222
 			_, err := client.Ping(context.Background())
223 223
 			assert.Check(t, is.Error(err, tc.expected))
224
-			assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
224
+			assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
225 225
 		})
226 226
 	}
227 227
 }
... ...
@@ -240,7 +240,7 @@ func TestInfiniteError(t *testing.T) {
240 240
 	}
241 241
 
242 242
 	_, err := client.Ping(context.Background())
243
-	assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
243
+	assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
244 244
 	assert.Check(t, is.ErrorContains(err, "request returned Internal Server Error"))
245 245
 }
246 246
 
... ...
@@ -258,7 +258,6 @@ func TestCanceledContext(t *testing.T) {
258 258
 	cancel()
259 259
 
260 260
 	_, err := client.sendRequest(ctx, http.MethodGet, testEndpoint, nil, nil, nil)
261
-	assert.Check(t, is.ErrorType(err, errdefs.IsCancelled))
262 261
 	assert.Check(t, is.ErrorIs(err, context.Canceled))
263 262
 }
264 263
 
... ...
@@ -278,6 +277,5 @@ func TestDeadlineExceededContext(t *testing.T) {
278 278
 	<-ctx.Done()
279 279
 
280 280
 	_, err := client.sendRequest(ctx, http.MethodGet, testEndpoint, nil, nil, nil)
281
-	assert.Check(t, is.ErrorType(err, errdefs.IsDeadline))
282 281
 	assert.Check(t, is.ErrorIs(err, context.DeadlineExceeded))
283 282
 }