[HttpClient] exceptions carry response
This commit is contained in:
parent
8af6395fa8
commit
103448cc67
@ -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