symfony: [VarDumper][HttpClient] Failed to dump response when StatusCode >= 500
Symfony version(s) affected: 4.4.* => 5.1.*
Description
When dumping a response, and if the response failed, Symfony Crash
How to reproduce
With a fresh symfony, put the following code in a controller:
symfony new --full test
cd test
bin/console make:controller Foobar
Edit Foobar and add:
$c = HttpClient::create();
$r = $c->request('GET', 'https://httpbin.org/status/500');
dd($r);
then run:
symfony serve
Then open http://127.0.0.1:8000/foobar
Additional context
It results in a blank page. In the symfony
logs:
Feb 17 16:04:14 |INFO | REQUES Matched route "homepage". method="GET" request_uri="https://127.0.0.1:8000/" route="homepage" route_parameters={"_controller":"App\\Controller\\HomepageController::index","_route":"homepage"}
Feb 17 16:04:15 |ERROR| PHP PHP Fatal error: Uncaught Symfony\Component\HttpClient\Exception\ServerException: HTTP/2 500 returned for "https://httpbin.org/status/500". in /tmp/test/vendor/symfony/http-client/Response/ResponseTrait.php:280
Feb 17 16:04:15 |DEBUG| PHP Stack trace:
Feb 17 16:04:15 |DEBUG| PHP #0 /tmp/test/vendor/symfony/http-client/Response/ResponseTrait.php(299): Symfony\Component\HttpClient\Response\CurlResponse->checkStatusCode()
Feb 17 16:04:15 |DEBUG| PHP #1 /tmp/test/vendor/symfony/http-client/Response/CurlResponse.php(186): Symfony\Component\HttpClient\Response\CurlResponse->doDestruct()
Feb 17 16:04:15 |DEBUG| PHP #2 [internal function]: Symfony\Component\HttpClient\Response\CurlResponse->__destruct()
Feb 17 16:04:15 |DEBUG| PHP #3 {main}
Feb 17 16:04:15 |DEBUG| PHP thrown in /tmp/test/vendor/symfony/http-client/Response/ResponseTrait.php on line 280
Feb 17 16:04:15 |ERROR| SERVER GET (500) / ip="127.0.0.1"
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (15 by maintainers)
Anyone to dig and debug this?
@Aerendir A blank page should never happen 😬 ; This is not because the behavior has already been experienced that we should not fix it
I tried your patch, and I still get a blank page. And this is normal. No exception are thrown here. So it does not change anything.
But thanks for your research on the topic.
I don’t understand the problem…
This is a behavior I have experimented before: when the variable you pass to
dump()
or todd()
throws an exception, the functions don’t print anything.Which is exactly the bug?
If you edit your code with something like this, it should work:
Does it?