8000 [9.x] Fix Http Client `throw` boolean parameter of `retry` method by gdebrauwer · Pull Request #41762 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] Fix Http Client throw boolean parameter of retry method #41762

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

Merged
merged 3 commits into from
Mar 31, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to 8000
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix retryThrow behavior
  • Loading branch information
gdebrauwer committed Mar 31, 2022
commit 406a51f719a5271e66246076b240e3054f9df035
12 changes: 10 additions & 2 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,19 @@ public function send(string $method, string $url, array $options = [])
return $this->makePromise($method, $url, $options);
}

return retry($this->tries ?? 1, function () use ($method, $url, $options) {
$attempt = 0;

return retry($this->tries ?? 1, function () use ($method, $url, $options, &$attempt) {
$attempt++;

try {
return tap(new Response($this->sendRequest($method, $url, $options)), function ($response) {
return tap(new Response($this->sendRequest($method, $url, $options)), function ($response) use ($attempt) {
$this->populateResponse($response);

if ($attempt < $this->tries && ! $response->successful()) {
$response->throw();
}

if ($this->tries > 1 && $this->retryThrow && ! $response->successful()) {
$response->throw();
}
Expand Down
0