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