From 103448cc672d81f7914049d0e0a78e0b172a7bc4 Mon Sep 17 00:00:00 2001 From: Anton Chernikov Date: Thu, 14 Mar 2019 13:49:27 +0300 Subject: [PATCH] [HttpClient] exceptions carry response --- .../Exception/HttpExceptionTrait.php | 8 ++++++ .../Exception/ClientExceptionInterface.php | 2 +- .../Exception/HttpExceptionInterface.php | 26 +++++++++++++++++++ .../RedirectionExceptionInterface.php | 2 +- .../Exception/ServerExceptionInterface.php | 2 +- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Contracts/HttpClient/Exception/HttpExceptionInterface.php diff --git a/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php b/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php index 48f7b880eb..befada6397 100644 --- a/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php +++ b/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php @@ -20,8 +20,11 @@ use Symfony\Contracts\HttpClient\ResponseInterface; */ trait HttpExceptionTrait { + private $response; + public function __construct(ResponseInterface $response) { + $this->response = $response; $code = $response->getInfo('http_code'); $url = $response->getInfo('url'); $message = sprintf('HTTP %d returned for URL "%s".', $code, $url); @@ -35,4 +38,9 @@ trait HttpExceptionTrait parent::__construct($message, $code); } + + public function getResponse(): ResponseInterface + { + return $this->response; + } } diff --git a/src/Symfony/Contracts/HttpClient/Exception/ClientExceptionInterface.php b/src/Symfony/Contracts/HttpClient/Exception/ClientExceptionInterface.php index a5f81dc146..5b5fa5084e 100644 --- a/src/Symfony/Contracts/HttpClient/Exception/ClientExceptionInterface.php +++ b/src/Symfony/Contracts/HttpClient/Exception/ClientExceptionInterface.php @@ -18,6 +18,6 @@ namespace Symfony\Contracts\HttpClient\Exception; * * @experimental in 1.1 */ -interface ClientExceptionInterface extends ExceptionInterface +interface ClientExceptionInterface extends HttpExceptionInterface { } diff --git a/src/Symfony/Contracts/HttpClient/Exception/HttpExceptionInterface.php b/src/Symfony/Contracts/HttpClient/Exception/HttpExceptionInterface.php new file mode 100644 index 0000000000..0e9f39f6ee --- /dev/null +++ b/src/Symfony/Contracts/HttpClient/Exception/HttpExceptionInterface.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\HttpClient\Exception; + +use Symfony\Contracts\HttpClient\ResponseInterface; + +/** + * Base interface for HTTP-related exceptions. + * + * @author Anton Chernikov + * + * @experimental in 1.1 + */ +interface HttpExceptionInterface extends ExceptionInterface +{ + public function getResponse(): ResponseInterface; +} diff --git a/src/Symfony/Contracts/HttpClient/Exception/RedirectionExceptionInterface.php b/src/Symfony/Contracts/HttpClient/Exception/RedirectionExceptionInterface.php index 208d692c62..8cdd3e70d7 100644 --- a/src/Symfony/Contracts/HttpClient/Exception/RedirectionExceptionInterface.php +++ b/src/Symfony/Contracts/HttpClient/Exception/RedirectionExceptionInterface.php @@ -18,6 +18,6 @@ namespace Symfony\Contracts\HttpClient\Exception; * * @experimental in 1.1 */ -interface RedirectionExceptionInterface extends ExceptionInterface +interface RedirectionExceptionInterface extends HttpExceptionInterface { } diff --git a/src/Symfony/Contracts/HttpClient/Exception/ServerExceptionInterface.php b/src/Symfony/Contracts/HttpClient/Exception/ServerExceptionInterface.php index a1be7d4f7f..f994ba2ddc 100644 --- a/src/Symfony/Contracts/HttpClient/Exception/ServerExceptionInterface.php +++ b/src/Symfony/Contracts/HttpClient/Exception/ServerExceptionInterface.php @@ -18,6 +18,6 @@ namespace Symfony\Contracts\HttpClient\Exception; * * @experimental in 1.1 */ -interface ServerExceptionInterface extends ExceptionInterface +interface ServerExceptionInterface extends HttpExceptionInterface { }