Skip to content

Commit

Permalink
feature #30567 [HttpClient] exceptions carry response (antonch1989)
Browse files Browse the repository at this point in the history
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
-------

103448c [HttpClient] exceptions carry response
  • Loading branch information
fabpot committed Mar 19, 2019
2 parents b15eee9 + 103448c commit bff9e68
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
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;
}
}
Expand Up @@ -18,6 +18,6 @@
*
* @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;
}
Expand Up @@ -18,6 +18,6 @@
*
* @experimental in 1.1
*/
interface RedirectionExceptionInterface extends ExceptionInterface
interface RedirectionExceptionInterface extends HttpExceptionInterface
{
}
Expand Up @@ -18,6 +18,6 @@
*
* @experimental in 1.1
*/
interface ServerExceptionInterface extends ExceptionInterface
interface ServerExceptionInterface extends HttpExceptionInterface
{
}

0 comments on commit bff9e68

Please sign in to comment.