Skip to content

[HttpClient] exceptions carry response #30567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -35,4 +38,9 @@ public function __construct(ResponseInterface $response)

parent::__construct($message, $code);
}

public function getResponse(): ResponseInterface
{
return $this->response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*
* @experimental in 1.1
*/
interface ClientExceptionInterface extends ExceptionInterface
interface ClientExceptionInterface extends HttpExceptionInterface
{
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*
* @experimental in 1.1
*/
interface RedirectionExceptionInterface extends ExceptionInterface
interface RedirectionExceptionInterface extends HttpExceptionInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*
* @experimental in 1.1
*/
interface ServerExceptionInterface extends ExceptionInterface
interface ServerExceptionInterface extends HttpExceptionInterface
{
}