Skip to content

Commit 46b9092

Browse files
committed
Throw a \RuntimeException whenever a curl request fails (#90)
1 parent e9a04d9 commit 46b9092

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Client.php

+8
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ private function parseResponse($channel, $content)
415415
$headerSize = curl_getinfo($channel, CURLINFO_HEADER_SIZE);
416416
$statusCode = curl_getinfo($channel, CURLINFO_HTTP_CODE);
417417

418+
if ($statusCode === 0) {
419+
throw new \RuntimeException(curl_error($channel));
420+
}
421+
418422
$responseBody = substr($content, $headerSize);
419423

420424
$responseHeaders = substr($content, 0, $headerSize);
@@ -453,6 +457,8 @@ private function retryRequest(array $responseHeaders, $method, $url, $body, $hea
453457
* @param bool $retryOnLimit should retry if rate limit is reach?
454458
*
455459
* @return Response object
460+
*
461+
* @throws \RuntimeException
456462
*/
457463
public function makeRequest($method, $url, $body = null, $headers = null, $retryOnLimit = false)
458464
{
@@ -481,6 +487,8 @@ public function makeRequest($method, $url, $body = null, $headers = null, $retry
481487
* @param array $requests
482488
*
483489
* @return Response[]
490+
*
491+
* @throws \RuntimeException
484492
*/
485493
public function makeAllRequests(array $requests = [])
486494
{

test/unit/ClientTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ public function testCreateCurlOptionsWithBodyAndHeaders()
195195
], $result);
196196
}
197197

198+
/**
199+
* @expectedException \RuntimeException
200+
* @expectedExceptionMessageRegExp /SSL certificate problem/
201+
*/
202+
public function testMakeRequestWithUntrustedRootCert()
203+
{
204+
$client = new Client('https://untrusted-root.badssl.com/');
205+
$client->makeRequest('GET', 'https://untrusted-root.badssl.com/');
206+
}
207+
198208
/**
199209
* @param object $obj
200210
* @param string $name

0 commit comments

Comments
 (0)