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 { }