Skip to content

Commit

Permalink
Merge pull request #2108 from wwulfric/master
Browse files Browse the repository at this point in the history
curl error msg for low version
  • Loading branch information
sagikazarmark committed Apr 15, 2019
2 parents b44a880 + f5203f7 commit 3d499a1
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Handler/CurlFactory.php
Expand Up @@ -14,6 +14,9 @@
*/
class CurlFactory implements CurlFactoryInterface
{
const CURL_VERSION_STR = 'curl_version';
const LOW_CURL_VERSION_NUMBER = '7.21.2';

/** @var array */
private $handles = [];

Expand Down Expand Up @@ -137,6 +140,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,13 +176,22 @@ private static function createRejection(EasyHandle $easy, array $ctx)
)
);
}

$message = sprintf(
'cURL error %s: %s (%s)',
$ctx['errno'],
$ctx['error'],
'see https://curl.haxx.se/libcurl/c/libcurl-errors.html'
);
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 3d499a1

Please sign in to comment.