Skip to content

Commit 771ecd6

Browse files
committed
Throw NetworkException on network errors.
1 parent 4f33a3d commit 771ecd6

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Changed
6+
7+
- `Client::sendRequest` now throws NetworkException on network errors.
8+
9+
310
## 1.5.1 - 2016-08-29
411

512
### Fixed

src/Client.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Http\Client\Curl;
33

44
use Http\Client\Exception;
5-
use Http\Client\Exception\RequestException;
65
use Http\Client\HttpAsyncClient;
76
use Http\Client\HttpClient;
87
use Http\Discovery\MessageFactoryDiscovery;
@@ -99,11 +98,13 @@ public function __destruct()
9998
*
10099
* @return ResponseInterface
101100
*
101+
* @throws \Http\Client\Exception\NetworkException In case of network problems.
102+
* @throws \Http\Client\Exception\RequestException On invalid request.
102103
* @throws \InvalidArgumentException For invalid header names or values.
103104
* @throws \RuntimeException If creating the body stream fails.
104105
* @throws \UnexpectedValueException if unsupported HTTP version requested
105-
* @throws RequestException
106106
*
107+
* @since x.x Throw NetworkException on network errors.
107108
* @since 1.0
108109
*/
109110
public function sendRequest(RequestInterface $request)
@@ -120,8 +121,19 @@ public function sendRequest(RequestInterface $request)
120121
curl_setopt_array($this->handle, $options);
121122
curl_exec($this->handle);
122123

123-
if (curl_errno($this->handle) > 0) {
124-
throw new RequestException(curl_error($this->handle), $request);
124+
$errno = curl_errno($this->handle);
125+
switch ($errno) {
126+
case CURLE_OK:
127+
// All OK, no actions needed.
128+
break;
129+
case CURLE_COULDNT_RESOLVE_PROXY:
130+
case CURLE_COULDNT_RESOLVE_HOST:
131+
case CURLE_COULDNT_CONNECT:
132+
case CURLE_OPERATION_TIMEOUTED:
133+
case CURLE_SSL_CONNECT_ERROR:
134+
throw new Exception\NetworkException(curl_error($this->handle), $request);
135+
default:
136+
throw new Exception\RequestException(curl_error($this->handle), $request);
125137
}
126138

127139
$response = $responseBuilder->getResponse();

0 commit comments

Comments
 (0)