THRIFT-4641: Check HTTP Status Code in TCurlClient
diff --git a/lib/php/lib/Transport/TCurlClient.php b/lib/php/lib/Transport/TCurlClient.php
index f51fa88..2ca4f65 100644
--- a/lib/php/lib/Transport/TCurlClient.php
+++ b/lib/php/lib/Transport/TCurlClient.php
@@ -220,12 +220,18 @@
curl_setopt(self::$curlHandle, CURLOPT_URL, $fullUrl);
$this->response_ = curl_exec(self::$curlHandle);
- // Connect failed?
- if (!$this->response_) {
+ $code = curl_getinfo(self::$curlHandle, CURLINFO_HTTP_CODE);
+
+ // Handle non 200 status code / connect failure
+ if (!$this->response_ || $code !== 200) {
curl_close(self::$curlHandle);
self::$curlHandle = null;
+ $this->response_ = null;
$error = 'TCurlClient: Could not connect to ' . $fullUrl;
- throw new TTransportException($error, TTransportException::NOT_OPEN);
+ if ($code) {
+ $error .= ', HTTP status code: ' . $code;
+ }
+ throw new TTransportException($error, TTransportException::UNKNOWN);
}
}