@@ -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