diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index 456bf6c0608d..4fc0d324cb4e 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -708,7 +708,7 @@ public function send(string $method, string $url, array $options = []) return $this->makePromise($method, $url, $options); } - $shouldRetry = true; + $shouldRetry = null; return retry($this->tries ?? 1, function ($attempt) use ($method, $url, $options, &$shouldRetry) { try { @@ -740,8 +740,12 @@ public function send(string $method, string $url, array $options = []) throw new ConnectionException($e->getMessage(), 0, $e); } - }, $this->retryDelay ?? 100, function () use (&$shouldRetry) { - return $shouldRetry; + }, $this->retryDelay ?? 100, function ($exception) use (&$shouldRetry) { + $result = $shouldRetry ?? ($this->retryWhenCallback ? call_user_func($this->retryWhenCallback, $exception, $this) : true); + + $shouldRetry = null; + + return $result; }); }