fix(log): don't conflate body drain errors with HTTP errors

Christian Rocha created

Change summary

internal/log/http.go | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

Detailed changes

internal/log/http.go 🔗

@@ -63,6 +63,10 @@ func (h *HTTPRoundTripLogger) RoundTrip(req *http.Request) (*http.Response, erro
 	}
 
 	save, resp.Body, err = drainBody(resp.Body)
+	if err != nil {
+		slog.Error("Failed to drain response body", "error", err)
+		return resp, err
+	}
 	if slog.Default().Enabled(req.Context(), slog.LevelDebug) {
 		slog.Debug(
 			"HTTP Response",
@@ -72,10 +76,9 @@ func (h *HTTPRoundTripLogger) RoundTrip(req *http.Request) (*http.Response, erro
 			"body", bodyToString(save),
 			"content_length", resp.ContentLength,
 			"duration_ms", duration.Milliseconds(),
-			"error", err,
 		)
 	}
-	return resp, err
+	return resp, nil
 }
 
 func bodyToString(body io.ReadCloser) string {