Skip to content

Commit 148adab

Browse files
authored
Update client error logging (#59)
* update client error logging * add comments
1 parent dec8718 commit 148adab

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

pkg/deploymentrecord/client.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,18 @@ 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+
// Drain and close response body to enable connection reuse
245+
_, _ = io.Copy(io.Discard, resp.Body)
246+
_ = resp.Body.Close()
248247
dtmetrics.PostDeploymentRecordOk.Inc()
249248
return nil
250249
}
251250

251+
// Drain and close response body to enable connection reuse by reading body for error logging
252+
body, _ := io.ReadAll(resp.Body)
253+
_ = resp.Body.Close()
254+
252255
lastErr = fmt.Errorf("unexpected status code: %d", resp.StatusCode)
253256

254257
// Don't retry on client errors (4xx) except for 429
@@ -257,10 +260,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
257260
dtmetrics.PostDeploymentRecordClientError.Inc()
258261
slog.Warn("client error, aborting",
259262
"attempt", attempt,
260-
"error", lastErr)
263+
"error", lastErr,
264+
"status_code", resp.StatusCode,
265+
"msg", string(body),
266+
)
261267
return &ClientError{err: lastErr}
262268
}
263269
dtmetrics.PostDeploymentRecordSoftFail.Inc()
270+
slog.Debug("retriable server error",
271+
"attempt", attempt,
272+
"status_code", resp.StatusCode,
273+
"msg", string(body),
274+
)
264275
}
265276

266277
dtmetrics.PostDeploymentRecordHardFail.Inc()

0 commit comments

Comments
 (0)