Skip to content

Commit 90ca404

Browse files
bug #31586 [HttpClient] display proper error message on TransportException when curl is used (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] display proper error message on TransportException when curl is used | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Reported independently by @GawainLynch and @tgalopin: the message of TransportException is currently empty when using CurlHttpClient. This now displays e.g. ``` [Symfony\Component\HttpClient\Exception\TransportException] Couldn't connect to server for http://localhost:8000/index.html ``` Commits ------- 3273109 [HttpClient] display proper error message on TransportException when curl is used
2 parents 1cd99ea + 3273109 commit 90ca404

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(ResponseInterface $response)
2727
$this->response = $response;
2828
$code = $response->getInfo('http_code');
2929
$url = $response->getInfo('url');
30-
$message = sprintf('HTTP %d returned for URL "%s".', $code, $url);
30+
$message = sprintf('HTTP %d returned for "%s".', $code, $url);
3131

3232
$httpCodeFound = false;
3333
$isJson = false;
@@ -37,7 +37,7 @@ public function __construct(ResponseInterface $response)
3737
break;
3838
}
3939

40-
$message = sprintf('%s returned for URL "%s".', $h, $url);
40+
$message = sprintf('%s returned for "%s".', $h, $url);
4141
$httpCodeFound = true;
4242
}
4343

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private static function perform(CurlClientState $multi, array &$responses = null
245245

246246
while ($info = curl_multi_info_read($multi->handle)) {
247247
$multi->handlesActivity[(int) $info['handle']][] = null;
248-
$multi->handlesActivity[(int) $info['handle']][] = \in_array($info['result'], [\CURLE_OK, \CURLE_TOO_MANY_REDIRECTS], true) || (\CURLE_WRITE_ERROR === $info['result'] && 'destruct' === @curl_getinfo($info['handle'], CURLINFO_PRIVATE)) ? null : new TransportException(curl_error($info['handle']));
248+
$multi->handlesActivity[(int) $info['handle']][] = \in_array($info['result'], [\CURLE_OK, \CURLE_TOO_MANY_REDIRECTS], true) || (\CURLE_WRITE_ERROR === $info['result'] && 'destruct' === @curl_getinfo($info['handle'], CURLINFO_PRIVATE)) ? null : new TransportException(sprintf('%s for"%s".', curl_strerror($info['result']), curl_getinfo($info['handle'], CURLINFO_EFFECTIVE_URL)));
249249
}
250250
} finally {
251251
self::$performing = false;

0 commit comments

Comments
 (0)