Skip to content

Commit c4bc126

Browse files
authored
Allow middleware exceptions to be retried (#55343)
1 parent 58862a8 commit c4bc126

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ public function send(string $method, string $url, array $options = [])
947947
throw $exception;
948948
}
949949
}, $this->retryDelay ?? 100, function ($exception) use (&$shouldRetry) {
950-
$result = $shouldRetry ?? ($this->retryWhenCallback ? call_user_func($this->retryWhenCallback, $exception, $this, $this->request->toPsrRequest()->getMethod()) : true);
950+
$result = $shouldRetry ?? ($this->retryWhenCallback ? call_user_func($this->retryWhenCallback, $exception, $this, $this->request?->toPsrRequest()->getMethod()) : true);
951951

952952
$shouldRetry = null;
953953

tests/Http/HttpClientTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,22 @@ public function testExceptionThrownInRetryCallbackIsReturnedWithoutRetryingInPoo
23342334
$this->factory->assertSentCount(1);
23352335
}
23362336

2337+
public function testExceptionThrowInMiddlewareAllowsRetry()
2338+
{
2339+
$middleware = Middleware::mapRequest(function (RequestInterface $request) {
2340+
throw new RuntimeException;
2341+
});
2342+
2343+
$this->expectException(RuntimeException::class);
2344+
2345+
$this->factory->fake(function (Request $request) {
2346+
return $this->factory->response('Fake');
2347+
})->withMiddleware($middleware)
2348+
->retry(3, 1, function (Exception $exception, PendingRequest $request) {
2349+
return true;
2350+
})->post('https://example.com');
2351+
}
2352+
23372353
public function testRequestsWillBeWaitingSleepMillisecondsReceivedInBackoffArray()
23382354
{
23392355
Sleep::fake();

0 commit comments

Comments
 (0)