Skip to content

Commit 96e70a4

Browse files
[HttpClient] fix exception in case of PSR17 discovery failure
1 parent b9a0b33 commit 96e70a4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/Symfony/Component/HttpClient/HttplugClient.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Http\Client\Exception\RequestException;
1717
use Http\Client\HttpAsyncClient;
1818
use Http\Client\HttpClient as HttplugInterface;
19+
use Http\Discovery\Exception\NotFoundException;
1920
use Http\Discovery\Psr17FactoryDiscovery;
2021
use Http\Message\RequestFactory;
2122
use Http\Message\StreamFactory;
@@ -75,9 +76,13 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI
7576
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
7677
}
7778

78-
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
79-
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
80-
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
79+
try {
80+
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
81+
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
82+
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
83+
} catch (NotFoundException $e) {
84+
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
85+
}
8186
}
8287

8388
$this->waitLoop = new HttplugWaitLoop($this->client, $this->promisePool, $this->responseFactory, $this->streamFactory);

src/Symfony/Component/HttpClient/Psr18Client.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpClient;
1313

14+
use Http\Discovery\Exception\NotFoundException;
1415
use Http\Discovery\Psr17FactoryDiscovery;
1516
use Nyholm\Psr7\Factory\Psr17Factory;
1617
use Nyholm\Psr7\Request;
@@ -68,9 +69,13 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI
6869
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
6970
}
7071

71-
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
72-
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
73-
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
72+
try {
73+
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
74+
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
75+
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
76+
} catch (NotFoundException $e) {
77+
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
78+
}
7479
}
7580

7681
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy