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

Propogate Do() HTTP error up when retries are exceeded #70

Merged
merged 1 commit into from
Jun 15, 2020

Conversation

theckman
Copy link
Contributor

Add propagation of the HTTP request/response error up the call stack when the
number of retries are exceeded. Because the ErrorHandler does not receive a copy
of the request, it's impossible to use the ErrorHandler to generate an enhanced
version of the default Retries Exceeded error message.

This change takes the non-API breaking approach to solving this, by including
the error string in the returned error (if an error has occured).

Fixes #69

@hashicorp-cla
Copy link

hashicorp-cla commented Oct 11, 2019

CLA assistant check
All committers have signed the CLA.

@theckman theckman force-pushed the return_err branch 4 times, most recently from e5a3fae to 9d0ede6 Compare October 15, 2019 20:53
@theckman
Copy link
Contributor Author

@evanphx I think this is ready for review if you're interested / when you have a moment.

Copy link
Contributor

@evanphx evanphx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few issues that need to get sorted out.

client.go Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
@tgropper
Copy link

Wouldn't it be better if we change the returned error to a typed model (instead of errors.errorString) and wrap the original request error?

Also it would be nice that if there is a non-successful status code we add to the error the response body, considering the server may return a more detailed error description.

@theckman theckman force-pushed the return_err branch 3 times, most recently from 237475a to 4fbec8c Compare April 15, 2020 01:36
@theckman
Copy link
Contributor Author

@tgropper would you be able to clarify what you mean by a "typed model"? I'm not familiar with that term.

To your second point, could you clarify that a bit more? Are you suggesting we read the response body and append it to the error value we return?

@theckman theckman force-pushed the return_err branch 2 times, most recently from 613620c to 4819acc Compare April 15, 2020 01:41
@theckman theckman force-pushed the return_err branch 2 times, most recently from 8326782 to 494eb9a Compare June 9, 2020 07:22
@theckman
Copy link
Contributor Author

theckman commented Jun 9, 2020

@evanphx this is ready for review, if you're still willing/able.

Add propagation of the HTTP request/response error up the call stack when the
number of retries are exceeded. Because the ErrorHandler does not receive a copy
of the request, it's impossible to use the ErrorHandler to generate an enhanced
version of the default Retries Exceeded error message.

This change takes the non-API breaking approach to solving this, by including
the error string in the returned error (if an error has occurred).

Because the error string returned from `Do()` uses `%w`, this change requires Go
1.13+.

Fixes hashicorp#69
client.go Show resolved Hide resolved
@evanphx evanphx self-requested a review June 10, 2020 04:45
Copy link
Contributor

@evanphx evanphx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@jefferai
Copy link
Member

LGTM too, merging! Thanks!

jefferai pushed a commit that referenced this pull request Nov 4, 2020
* Realign behavior of ErrorPropagatedRetryPolicy with DefaultRetryPolicy

ErrorPropagatedRetryPolicy should have been modified in #100,
but failed to... probably because it has been merged approximately at the same time
as #70 (the PR adding ErrorPropagatedRetryPolicy).

* Remove code duplication between DefaultRetryPolicy and ErrorPropagatedRetryPolicy
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

Successfully merging this pull request may close these issues.

HTTP Request error should be propagated to the caller
6 participants