diff --git a/pkg/deploymentrecord/client.go b/pkg/deploymentrecord/client.go index c335e87..fe50b74 100644 --- a/pkg/deploymentrecord/client.go +++ b/pkg/deploymentrecord/client.go @@ -240,15 +240,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error { continue } - // Drain and close response body to enable connection reuse - _, _ = io.Copy(io.Discard, resp.Body) - _ = resp.Body.Close() - if resp.StatusCode >= 200 && resp.StatusCode < 300 { + // Drain and close response body to enable connection reuse + _, _ = io.Copy(io.Discard, resp.Body) + _ = resp.Body.Close() dtmetrics.PostDeploymentRecordOk.Inc() return nil } + // Drain and close response body to enable connection reuse by reading body for error logging + body, _ := io.ReadAll(resp.Body) + _ = resp.Body.Close() + lastErr = fmt.Errorf("unexpected status code: %d", resp.StatusCode) // Don't retry on client errors (4xx) except for 429 @@ -257,10 +260,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error { dtmetrics.PostDeploymentRecordClientError.Inc() slog.Warn("client error, aborting", "attempt", attempt, - "error", lastErr) + "error", lastErr, + "status_code", resp.StatusCode, + "msg", string(body), + ) return &ClientError{err: lastErr} } dtmetrics.PostDeploymentRecordSoftFail.Inc() + slog.Debug("retriable server error", + "attempt", attempt, + "status_code", resp.StatusCode, + "msg", string(body), + ) } dtmetrics.PostDeploymentRecordHardFail.Inc()