[9.x] Fix Http Client throw
boolean parameter of retry
method
#41762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
According to PR #40079 and the documentation, the
throw
parameter of theretry
method can be used to not throw an exception when all retries have been attempted:This is currently not the case, because when
throw: false
, then it does not attempt any of the retries. It just throws the exception of the first attempt. This is caused by the following if-statement:This issue has also been reported by others: #41601.
Solution
To fix this, we could do the following:
The problem with this approach is when the
retryWhenCallback
closure returns false (which means that it should not retry) and thethrow
parameter is false, then an exception is still thrown.To fix that, we must call the
retryWhenCallback
before we throw any exception based on a response.We are almost there. The last issue we now have is when
retryThrow
boolean parameter is false andretryWhenCallback
closure returns false for a certain exception, then it will still retry. This can be fixed by remembering the result of theretryWhenCallback
closure and using it in thewhen
closure of the globalretry
helper method:I added the necessary tests for all these possibilities