Skip to content

Commit

Permalink
curl error msg for low version
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulfric Wang committed Aug 3, 2018
1 parent bd36885 commit bcfa6ba
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/Handler/CurlFactory.php
Expand Up @@ -14,6 +14,8 @@
*/
class CurlFactory implements CurlFactoryInterface
{
private const CURL_VERSION_STR = 'curl_version';
private const LOW_CURL_VERSION_NUMBER = '7.21.2';
/** @var array */
private $handles = [];

Expand Down Expand Up @@ -137,6 +139,7 @@ private static function finishError(
'errno' => $easy->errno,
'error' => curl_error($easy->handle),
] + curl_getinfo($easy->handle);
$ctx[self::CURL_VERSION_STR] = curl_version()['version'];
$factory->release($easy);

// Retry when nothing is present or when curl failed to rewind.
Expand Down Expand Up @@ -172,14 +175,22 @@ private static function createRejection(EasyHandle $easy, array $ctx)
)
);
}

$message = sprintf(
'cURL error %s: %s (%s) for %s',
$ctx['errno'],
$ctx['error'],
'see https://curl.haxx.se/libcurl/c/libcurl-errors.html',
$easy->request->getUri()
);
if (version_compare($ctx[self::CURL_VERSION_STR], self::LOW_CURL_VERSION_NUMBER)) {
$message = sprintf(
'cURL error %s: %s (%s)',
$ctx['errno'],
$ctx['error'],
'see https://curl.haxx.se/libcurl/c/libcurl-errors.html',
);
} else {
$message = sprintf(
'cURL error %s: %s (%s) for %s',
$ctx['errno'],
$ctx['error'],
'see https://curl.haxx.se/libcurl/c/libcurl-errors.html',
$easy->request->getUri()
);
}

// Create a connection exception if it was a specific error code.
$error = isset($connectionErrors[$easy->errno])
Expand Down

0 comments on commit bcfa6ba

Please sign in to comment.