From 10d96cb2439b7dbed742c82848e7b12869d5068b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 4 Jan 2019 09:03:11 +0100 Subject: [PATCH 1/4] Added HttpClientNoMatchException for HttpClientRouter --- src/Exception/HttpClientNoMatchException.php | 30 ++++++++++++++++++++ src/HttpClientRouter.php | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/Exception/HttpClientNoMatchException.php diff --git a/src/Exception/HttpClientNoMatchException.php b/src/Exception/HttpClientNoMatchException.php new file mode 100644 index 0000000..17f6687 --- /dev/null +++ b/src/Exception/HttpClientNoMatchException.php @@ -0,0 +1,30 @@ + + */ +class HttpClientNoMatchException extends TransferException +{ + private $request; + + public function __construct(string $message, RequestInterface $request, \Exception $previous = null) + { + $this->request = $request; + + parent::__construct($message, 0, $previous); + } + + public function getRequest(): RequestInterface + { + return $this->request; + } +} diff --git a/src/HttpClientRouter.php b/src/HttpClientRouter.php index 37f8c3c..ccd4a1c 100644 --- a/src/HttpClientRouter.php +++ b/src/HttpClientRouter.php @@ -4,7 +4,7 @@ namespace Http\Client\Common; -use Http\Client\Exception\RequestException; +use Http\Client\Common\Exception\HttpClientNoMatchException; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; use Http\Message\RequestMatcher; @@ -66,6 +66,6 @@ private function chooseHttpClient(RequestInterface $request) } } - throw new RequestException('No client found for the specified request', $request); + throw new HttpClientNoMatchException('No client found for the specified request', $request); } } From c67d2d411966589f14a99ece6eb0bedfbd00e611 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 4 Jan 2019 10:02:36 +0100 Subject: [PATCH 2/4] Minor --- spec/HttpClientRouterSpec.php | 5 +++-- src/Exception/HttpClientNoMatchException.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/HttpClientRouterSpec.php b/spec/HttpClientRouterSpec.php index a409203..d98effc 100644 --- a/spec/HttpClientRouterSpec.php +++ b/spec/HttpClientRouterSpec.php @@ -2,6 +2,7 @@ namespace spec\Http\Client\Common; +use Http\Client\Common\Exception\HttpClientNoMatchException; use Http\Client\Common\HttpClientRouter; use Http\Message\RequestMatcher; use Http\Client\HttpAsyncClient; @@ -58,7 +59,7 @@ public function it_throw_exception_on_send_request(RequestMatcher $matcher, Http $this->addClient($client, $matcher); $matcher->matches($request)->willReturn(false); - $this->shouldThrow(RequestException::class)->duringSendRequest($request); + $this->shouldThrow(HttpClientNoMatchException::class)->duringSendRequest($request); } public function it_throw_exception_on_send_async_request(RequestMatcher $matcher, HttpAsyncClient $client, RequestInterface $request) @@ -66,6 +67,6 @@ public function it_throw_exception_on_send_async_request(RequestMatcher $matcher $this->addClient($client, $matcher); $matcher->matches($request)->willReturn(false); - $this->shouldThrow(RequestException::class)->duringSendAsyncRequest($request); + $this->shouldThrow(HttpClientNoMatchException::class)->duringSendAsyncRequest($request); } } diff --git a/src/Exception/HttpClientNoMatchException.php b/src/Exception/HttpClientNoMatchException.php index 17f6687..437467c 100644 --- a/src/Exception/HttpClientNoMatchException.php +++ b/src/Exception/HttpClientNoMatchException.php @@ -12,7 +12,7 @@ * * @author Tobias Nyholm */ -class HttpClientNoMatchException extends TransferException +final class HttpClientNoMatchException extends TransferException { private $request; From 70b5f39f759d28f9babf9bc2f4645f8fa0cf8866 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 4 Jan 2019 10:10:57 +0100 Subject: [PATCH 3/4] unused use statement --- spec/HttpClientRouterSpec.php | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/HttpClientRouterSpec.php b/spec/HttpClientRouterSpec.php index d98effc..f90c034 100644 --- a/spec/HttpClientRouterSpec.php +++ b/spec/HttpClientRouterSpec.php @@ -12,7 +12,6 @@ use Psr\Http\Message\ResponseInterface; use PhpSpec\ObjectBehavior; use Http\Client\Common\HttpClientRouterInterface; -use Http\Client\Exception\RequestException; class HttpClientRouterSpec extends ObjectBehavior { From 9e8e90f2b8f3eb47d4a42aaeb7b17ec78ca333b5 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 4 Jan 2019 10:12:47 +0100 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e5e0a0..2059785 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.0 (unreleased) ### Changed +- HttpClientRouter now throws a HttpClientNoMatchException instead of a RequestException if it can not find a client for the request. - RetryPlugin will no longer retry requests when the response failed with a HTTP code < 500. - Abstract method `HttpClientPool::chooseHttpClient()` has now an explicit return type (`Http\Client\Common\HttpClientPoolItem`) - Interface method `Plugin::handleRequest(...)` has now an explicit return type (`Http\Promise\Promise`)