Skip to content

Commit dbb6c4b

Browse files
authored
Merge pull request #163 from Nyholm/issue-160
Updated the exceptions we are using
2 parents ff46215 + 6871362 commit dbb6c4b

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Plugin/HistoryPlugin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Http\Client\Common\Plugin;
66

77
use Http\Client\Common\Plugin;
8-
use Http\Client\Exception;
98
use Http\Promise\Promise;
9+
use Psr\Http\Client\ClientExceptionInterface;
1010
use Psr\Http\Message\RequestInterface;
1111
use Psr\Http\Message\ResponseInterface;
1212

@@ -40,7 +40,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
4040
$journal->addSuccess($request, $response);
4141

4242
return $response;
43-
}, function (Exception $exception) use ($request, $journal) {
43+
}, function (ClientExceptionInterface $exception) use ($request, $journal) {
4444
$journal->addFailure($request, $exception);
4545

4646
throw $exception;

src/Plugin/Journal.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Http\Client\Common\Plugin;
66

7-
use Http\Client\Exception;
7+
use Psr\Http\Client\ClientExceptionInterface;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
1010

@@ -26,8 +26,8 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons
2626
/**
2727
* Record a failed call.
2828
*
29-
* @param RequestInterface $request Request use to make the call
30-
* @param Exception $exception Exception returned by the call
29+
* @param RequestInterface $request Request use to make the call
30+
* @param ClientExceptionInterface $exception Exception returned by the call
3131
*/
32-
public function addFailure(RequestInterface $request, Exception $exception);
32+
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception);
3333
}

src/Plugin/RetryPlugin.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Http\Client\Common\Plugin;
66

77
use Http\Client\Common\Plugin;
8-
use Http\Client\Exception;
98
use Http\Client\Exception\HttpException;
109
use Http\Promise\Promise;
10+
use Psr\Http\Client\ClientExceptionInterface;
1111
use Psr\Http\Message\RequestInterface;
1212
use Psr\Http\Message\ResponseInterface;
1313
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -74,7 +74,7 @@ public function __construct(array $config = [])
7474
// do not retry client errors
7575
return $response->getStatusCode() >= 500 && $response->getStatusCode() < 600;
7676
},
77-
'exception_decider' => function (RequestInterface $request, Exception $e) {
77+
'exception_decider' => function (RequestInterface $request, ClientExceptionInterface $e) {
7878
// do not retry client errors
7979
return !$e instanceof HttpException || $e->getCode() >= 500 && $e->getCode() < 600;
8080
},
@@ -124,7 +124,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
124124
}
125125

126126
return $response;
127-
}, function (Exception $exception) use ($request, $next, $first, $chainIdentifier) {
127+
}, function (ClientExceptionInterface $exception) use ($request, $next, $first, $chainIdentifier) {
128128
if (!array_key_exists($chainIdentifier, $this->retryStorage)) {
129129
$this->retryStorage[$chainIdentifier] = 0;
130130
}
@@ -156,7 +156,7 @@ public static function defaultErrorResponseDelay(RequestInterface $request, Resp
156156
/**
157157
* @param int $retries The number of retries we made before. First time this get called it will be 0.
158158
*/
159-
public static function defaultExceptionDelay(RequestInterface $request, Exception $e, int $retries): int
159+
public static function defaultExceptionDelay(RequestInterface $request, ClientExceptionInterface $e, int $retries): int
160160
{
161161
return pow(2, $retries) * 500000;
162162
}

0 commit comments

Comments
 (0)