Skip to content

Commit ca8c6f4

Browse files
committed
address comments
1 parent bf817f8 commit ca8c6f4

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/deploymentrecord/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
267267
_ = resp.Body.Close()
268268

269269
switch {
270-
case resp.StatusCode == 404 && bytes.Contains(respBody, []byte("no artifacts found")):
270+
case resp.StatusCode == 404:
271271
// No artifact found
272272
dtmetrics.PostDeploymentRecordNoAttestation.Inc()
273273
slog.Debug("no artifact attestation found, no record created",
@@ -279,7 +279,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
279279
return &NoArtifactError{err: fmt.Errorf("no attestation found for %s", record.Digest)}
280280
case resp.StatusCode >= 400 && resp.StatusCode < 500:
281281
if resp.Header.Get("retry-after") != "" || resp.Header.Get("x-ratelimit-remaining") == "0" {
282-
// rate limited — retry with backoff
282+
// Rate limited — retry with backoff
283283
// Could be 403 or 429
284284
dtmetrics.PostDeploymentRecordRateLimited.Inc()
285285
slog.Warn("rate limited, retrying",

pkg/deploymentrecord/client_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,33 +356,33 @@ func TestPostOne(t *testing.T) {
356356
wantNoAttestation: 1,
357357
},
358358
{
359-
name: "404 without no artifacts found returns ClientError",
359+
name: "400 returns ClientError",
360360
record: testRecord(),
361361
handler: func(w http.ResponseWriter, _ *http.Request) {
362-
w.WriteHeader(http.StatusNotFound)
363-
_, _ = w.Write([]byte(`{"message":"not found"}`))
362+
w.WriteHeader(http.StatusBadRequest)
363+
_, _ = w.Write([]byte("bad request"))
364364
},
365365
wantErr: true,
366366
errType: &ClientError{},
367367
wantClientError: 1,
368368
},
369369
{
370-
name: "400 returns ClientError",
370+
name: "403 forbidden returns ClientError",
371371
record: testRecord(),
372372
handler: func(w http.ResponseWriter, _ *http.Request) {
373-
w.WriteHeader(http.StatusBadRequest)
374-
_, _ = w.Write([]byte("bad request"))
373+
w.WriteHeader(http.StatusForbidden)
374+
_, _ = w.Write([]byte(`{"message":"forbidden"}`))
375375
},
376376
wantErr: true,
377377
errType: &ClientError{},
378378
wantClientError: 1,
379379
},
380380
{
381-
name: "403 forbidden returns ClientError",
381+
name: "422 invalid body returns ClientError",
382382
record: testRecord(),
383383
handler: func(w http.ResponseWriter, _ *http.Request) {
384-
w.WriteHeader(http.StatusForbidden)
385-
_, _ = w.Write([]byte(`{"message":"forbidden"}`))
384+
w.WriteHeader(http.StatusUnprocessableEntity)
385+
_, _ = w.Write([]byte("invalid body"))
386386
},
387387
wantErr: true,
388388
errType: &ClientError{},

0 commit comments

Comments
 (0)