hashicorp / hashicorp/go-retryablehttp

RoundTripper returns a non-nil response and error

Open
#179 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
2.3k
Forks
298
PR merge metrics
No merged PRs in 30d

Description

The code in question here is within `RoundTripper.RoundTrip()` which, in the check for `url.Error`, returns both the response and an error.

https://github.com/hashicorp/go-retryablehttp/blob/master/roundtripper.go#L47

While this behavior is not explicitly disallowed by the interface, the [net/http.Client implementation](https://github.com/golang/go/blob/go1.19.5/src/net/http/client.go#L255) does check for this and will print a corresponding log error. This erroneous log message is particularly annoying when expecting all program output to be JSON, which is how I found this.

From [this conversation](https://github.com/golang/go/issues/7620), that validation is expected.

EDIT: Also of note, this is eluded to in the [docs of the net/http.RoundTripper interface](https://pkg.go.dev/net/http#RoundTripper) with the line "A non-nil err should be reserved for failure to obtain a response", but it could certainly be worded better/more explicitly on that side.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.