Skip to content

Commit

Permalink
Throw a \RuntimeException whenever a curl request fails (sendgrid#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Oct 2, 2018
1 parent e9a04d9 commit 75e0473
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 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
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/
*/
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 75e0473

Please sign in to comment.