Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PassthroughErrorHandler shouldn't pass an error if response is non-nil #156

Open
ericleb010 opened this issue Mar 8, 2022 · 0 comments
Open

Comments

@ericleb010
Copy link

ericleb010 commented Mar 8, 2022

The README for this package reads:

[...] if an error is returned by the client (connection errors, etc.), or if a 500-range response code is received (except 501), then a retry is invoked after a wait period. Otherwise, the response is returned and left to the caller to interpret.

However, as it stands, PassthroughErrorHandler doesn't seem to behave in a way that would accomplish this behaviour out of the box under normal circumstances. This is because it always passes to the caller of RoundTrip the final http.Response and the error from the call to CheckRetry. A default http.Client will actually throw away the response if an error is returned. So in the case where, for example, we exhaust all RetryMax attempts due to consecutive 5xx errors, the caller will never see the final response body.

PassthroughErrorHandler could be much more useful if it first checks for a non-nil response:

func PassthroughErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error) {
	if resp != nil {
		return resp, nil
	}
	return resp, err
}

This throws away the helpful CheckRetry error on the last request, but gives the caller the expected ability to distinguish unexpected HTTP status codes from connection errors. Or maybe I'm misinterpreting what purpose PassthroughErrorHandler has?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant