Skip to content

HTTP protocol doesn't return body response when retrying #1238

@arxeiss

Description

@arxeiss

Description
If I send event with HTTP protocol (without retrying), in the Result I can see also body response. This is useful to understand what went wrong.

However, if I send event with HTTP Protocol and passing retry options via context like

Send(cloudevents.ContextWithRetriesExponentialBackoff(ctx, time.Second, 3), evt)

I'm getting back only status code. Not the body itself.

Source of bug
I believe the issue is on line 181 in ⬇️ because you are expecting err is type of http.Result. But after retrying, it is protocol.Result.

if err != nil && !protocol.IsACK(err) {
var res *Result
if protocol.ResultAs(err, &res) {
if message, ok := msg.(*Message); ok {
buf := new(bytes.Buffer)
buf.ReadFrom(message.BodyReader)
errorStr := buf.String()
// If the error is not wrapped, then append the original error string.
if og, ok := err.(*Result); ok {
og.Format = og.Format + "%s"
og.Args = append(og.Args, errorStr)
err = og
} else {
err = NewResult(res.StatusCode, "%w: %s", err, errorStr)
}
}
}
}
return err

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions