From 844a1da56dde7ae641745a65a5adc635d4450bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20St=C3=A4bler?= Date: Mon, 17 Jun 2024 14:37:16 +0200 Subject: [PATCH] Propagate read error correctly in event-dispatcher (#8005) (#629) --- pkg/kncloudevents/event_dispatcher.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/kncloudevents/event_dispatcher.go b/pkg/kncloudevents/event_dispatcher.go index a1f18e21fb0..ddc9e5978f8 100644 --- a/pkg/kncloudevents/event_dispatcher.go +++ b/pkg/kncloudevents/event_dispatcher.go @@ -298,12 +298,12 @@ func (d *Dispatcher) executeRequest(ctx context.Context, target duckv1.Addressab dispatchInfo.ResponseHeader = response.Header body := new(bytes.Buffer) - _, readErr := body.ReadFrom(response.Body) + _, err = body.ReadFrom(response.Body) if isFailure(response.StatusCode) { // Read response body into dispatchInfo for failures - if readErr != nil && readErr != io.EOF { - dispatchInfo.ResponseBody = []byte(fmt.Sprintf("dispatch resulted in status \"%s\". Could not read response body: error: %s", response.Status, readErr.Error())) + if err != nil && err != io.EOF { + dispatchInfo.ResponseBody = []byte(fmt.Sprintf("dispatch resulted in status \"%s\". Could not read response body: error: %s", response.Status, err.Error())) } else { dispatchInfo.ResponseBody = body.Bytes() } @@ -314,8 +314,9 @@ func (d *Dispatcher) executeRequest(ctx context.Context, target duckv1.Addressab } var responseMessageBody []byte - if readErr != nil && readErr != io.EOF { - responseMessageBody = []byte(fmt.Sprintf("Failed to read response body: %s", readErr.Error())) + if err != nil && err != io.EOF { + responseMessageBody = []byte(fmt.Sprintf("Failed to read response body: %s", err.Error())) + dispatchInfo.ResponseCode = http.StatusInternalServerError } else { responseMessageBody = body.Bytes() dispatchInfo.ResponseBody = responseMessageBody