Skip to content

Commit b9335a3

Browse files
committed
update client error logging
1 parent dec8718 commit b9335a3

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pkg/deploymentrecord/client.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,17 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
240240
continue
241241
}
242242

243-
// Drain and close response body to enable connection reuse
244-
_, _ = io.Copy(io.Discard, resp.Body)
245-
_ = resp.Body.Close()
246-
247243
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
244+
_, _ = io.Copy(io.Discard, resp.Body)
245+
_ = resp.Body.Close()
248246
dtmetrics.PostDeploymentRecordOk.Inc()
249247
return nil
250248
}
251249

250+
// Read response body for error messages
251+
body, _ := io.ReadAll(resp.Body)
252+
_ = resp.Body.Close()
253+
252254
lastErr = fmt.Errorf("unexpected status code: %d", resp.StatusCode)
253255

254256
// Don't retry on client errors (4xx) except for 429
@@ -257,10 +259,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
257259
dtmetrics.PostDeploymentRecordClientError.Inc()
258260
slog.Warn("client error, aborting",
259261
"attempt", attempt,
260-
"error", lastErr)
262+
"error", lastErr,
263+
"status_code", resp.StatusCode,
264+
"msg", string(body),
265+
)
261266
return &ClientError{err: lastErr}
262267
}
263268
dtmetrics.PostDeploymentRecordSoftFail.Inc()
269+
slog.Debug("retriable server error",
270+
"attempt", attempt,
271+
"status_code", resp.StatusCode,
272+
"msg", string(body),
273+
)
264274
}
265275

266276
dtmetrics.PostDeploymentRecordHardFail.Inc()

0 commit comments

Comments
 (0)