feature #30567 [HttpClient] exceptions carry response (antonch1989)
This PR was squashed before being merged into the 4.3-dev branch (closes #30567).
Discussion
----------
[HttpClient] exceptions carry response
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #30502
| License | MIT
| Doc PR |
Commits
-------
103448cc67
[HttpClient] exceptions carry response
This commit is contained in:
commit
bff9e68bb4
@ -20,8 +20,11 @@ use Symfony\Contracts\HttpClient\ResponseInterface;
|
|||||||
*/
|
*/
|
||||||
trait HttpExceptionTrait
|
trait HttpExceptionTrait
|
||||||
{
|
{
|
||||||
|
private $response;
|
||||||
|
|
||||||
public function __construct(ResponseInterface $response)
|
public function __construct(ResponseInterface $response)
|
||||||
{
|
{
|
||||||
|
$this->response = $response;
|
||||||
$code = $response->getInfo('http_code');
|
$code = $response->getInfo('http_code');
|
||||||
$url = $response->getInfo('url');
|
$url = $response->getInfo('url');
|
||||||
$message = sprintf('HTTP %d returned for URL "%s".', $code, $url);
|
$message = sprintf('HTTP %d returned for URL "%s".', $code, $url);
|
||||||
@ -35,4 +38,9 @@ trait HttpExceptionTrait
|
|||||||
|
|
||||||
parent::__construct($message, $code);
|
parent::__construct($message, $code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getResponse(): ResponseInterface
|
||||||
|
{
|
||||||
|
return $this->response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ namespace Symfony\Contracts\HttpClient\Exception;
|
|||||||
*
|
*
|
||||||
* @experimental in 1.1
|
* @experimental in 1.1
|
||||||
*/
|
*/
|
||||||
interface ClientExceptionInterface extends ExceptionInterface
|
interface ClientExceptionInterface extends HttpExceptionInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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 <anton_ch1989@mail.ru>
|
||||||
|
*
|
||||||
|
* @experimental in 1.1
|
||||||
|
*/
|
||||||
|
interface HttpExceptionInterface extends ExceptionInterface
|
||||||
|
{
|
||||||
|
public function getResponse(): ResponseInterface;
|
||||||
|
}
|
@ -18,6 +18,6 @@ namespace Symfony\Contracts\HttpClient\Exception;
|
|||||||
*
|
*
|
||||||
* @experimental in 1.1
|
* @experimental in 1.1
|
||||||
*/
|
*/
|
||||||
interface RedirectionExceptionInterface extends ExceptionInterface
|
interface RedirectionExceptionInterface extends HttpExceptionInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ namespace Symfony\Contracts\HttpClient\Exception;
|
|||||||
*
|
*
|
||||||
* @experimental in 1.1
|
* @experimental in 1.1
|
||||||
*/
|
*/
|
||||||
interface ServerExceptionInterface extends ExceptionInterface
|
interface ServerExceptionInterface extends HttpExceptionInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user