Skip to content

Commit

Permalink
Propagate read error correctly in event-dispatcher (knative#8005) (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr authored Jun 17, 2024
1 parent 3894539 commit 844a1da
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/kncloudevents/event_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand Down

0 comments on commit 844a1da

Please sign in to comment.