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 48f7b880eba43..befada639795a 100644 --- a/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php +++ b/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php @@ -20,8 +20,11 @@ */ 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 @@ public function __construct(ResponseInterface $response) 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 a5f81dc1465bd..5b5fa5084eff2 100644 --- a/src/Symfony/Contracts/HttpClient/Exception/ClientExceptionInterface.php +++ b/src/Symfony/Contracts/HttpClient/Exception/ClientExceptionInterface.php @@ -18,6 +18,6 @@ * * @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 0000000000000..0e9f39f6ee827 --- /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 208d692c62409..8cdd3e70d76d0 100644 --- a/src/Symfony/Contracts/HttpClient/Exception/RedirectionExceptionInterface.php +++ b/src/Symfony/Contracts/HttpClient/Exception/RedirectionExceptionInterface.php @@ -18,6 +18,6 @@ * * @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 a1be7d4f7f0d7..f994ba2ddcbb6 100644 --- a/src/Symfony/Contracts/HttpClient/Exception/ServerExceptionInterface.php +++ b/src/Symfony/Contracts/HttpClient/Exception/ServerExceptionInterface.php @@ -18,6 +18,6 @@ * * @experimental in 1.1 */ -interface ServerExceptionInterface extends ExceptionInterface +interface ServerExceptionInterface extends HttpExceptionInterface { } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy