2
2
namespace Http \Client \Curl ;
3
3
4
4
use Http \Client \Exception ;
5
- use Http \Client \Exception \RequestException ;
6
5
use Http \Client \HttpAsyncClient ;
7
6
use Http \Client \HttpClient ;
8
7
use Http \Discovery \MessageFactoryDiscovery ;
@@ -99,11 +98,13 @@ public function __destruct()
99
98
*
100
99
* @return ResponseInterface
101
100
*
101
+ * @throws \Http\Client\Exception\NetworkException In case of network problems.
102
+ * @throws \Http\Client\Exception\RequestException On invalid request.
102
103
* @throws \InvalidArgumentException For invalid header names or values.
103
104
* @throws \RuntimeException If creating the body stream fails.
104
105
* @throws \UnexpectedValueException if unsupported HTTP version requested
105
- * @throws RequestException
106
106
*
107
+ * @since x.x Throw NetworkException on network errors.
107
108
* @since 1.0
108
109
*/
109
110
public function sendRequest (RequestInterface $ request )
@@ -120,8 +121,19 @@ public function sendRequest(RequestInterface $request)
120
121
curl_setopt_array ($ this ->handle , $ options );
121
122
curl_exec ($ this ->handle );
122
123
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 );
125
137
}
126
138
127
139
$ response = $ responseBuilder ->getResponse ();
0 commit comments