Set error code and error message when there is an error; Change http error code to http status code

This commit is contained in:
php-curl-class
2013-08-23 03:22:40 -07:00
parent eead7179d6
commit 83c7fc76ab
+5 -5
View File
@@ -86,10 +86,10 @@ class Curl {
$this->curl_error_code = curl_errno($this->curl);
$this->curl_error_message = curl_error($this->curl);
$this->curl_error = !($this->curl_error_code === 0);
$this->http_error_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
$this->http_error = in_array(floor($this->http_error_code / 100), array(4, 5));
$this->http_status_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
$this->http_error = in_array(floor($this->http_status_code / 100), array(4, 5));
$this->error = $this->curl_error || $this->http_error;
$this->error_code = $this->curl_error ? $this->curl_error_code : $this->http_error_code;
$this->error_code = $this->error ? ($this->curl_error ? $this->curl_error_code : $this->http_status_code) : 0;
$this->request_headers = preg_split('/\r\n/', curl_getinfo($this->curl, CURLINFO_HEADER_OUT), NULL, PREG_SPLIT_NO_EMPTY);
$this->response_headers = '';
@@ -102,7 +102,7 @@ class Curl {
$this->response_headers = preg_split('/\r\n/', $this->response_headers, NULL, PREG_SPLIT_NO_EMPTY);
}
$this->http_error_message = isset($this->response_headers['0']) ? $this->response_headers['0'] : '';
$this->http_error_message = $this->error ? (isset($this->response_headers['0']) ? $this->response_headers['0'] : '') : '';
$this->error_message = $this->curl_error ? $this->curl_error_message : $this->http_error_message;
return $this->error_code;
@@ -126,7 +126,7 @@ class Curl {
public $curl_error_message = NULL;
public $http_error = FALSE;
public $http_error_code = NULL;
public $http_status_code = 0;
public $http_error_message = NULL;
public $request_headers = NULL;