Skip to content

Commit

Permalink
Throw a \RuntimeException whenever a curl request fails (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Oct 2, 2018
1 parent e9a04d9 commit 74f74c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ private function parseResponse($channel, $content)
$headerSize = curl_getinfo($channel, CURLINFO_HEADER_SIZE);
$statusCode = curl_getinfo($channel, CURLINFO_HTTP_CODE);

if ($statusCode === 0) {
throw new \RuntimeException(curl_error($channel));
}

$responseBody = substr($content, $headerSize);

$responseHeaders = substr($content, 0, $headerSize);
Expand Down Expand Up @@ -453,6 +457,8 @@ private function retryRequest(array $responseHeaders, $method, $url, $body, $hea
* @param bool $retryOnLimit should retry if rate limit is reach?
*
* @return Response object
*
* @throws \RuntimeException
*/
public function makeRequest($method, $url, $body = null, $headers = null, $retryOnLimit = false)
{
Expand Down Expand Up @@ -481,6 +487,8 @@ public function makeRequest($method, $url, $body = null, $headers = null, $retry
* @param array $requests
*
* @return Response[]
*
* @throws \RuntimeException
*/
public function makeAllRequests(array $requests = [])
{
Expand Down
10 changes: 10 additions & 0 deletions test/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ public function testCreateCurlOptionsWithBodyAndHeaders()
], $result);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessageRegExp /SSL certificate problem/i
*/
public function testMakeRequestWithUntrustedRootCert()
{
$client = new Client('https://untrusted-root.badssl.com/');
$client->makeRequest('GET', 'https://untrusted-root.badssl.com/');
}

/**
* @param object $obj
* @param string $name
Expand Down

0 comments on commit 74f74c3

Please sign in to comment.