Merge pull request #385 from zachborboa/master

Include additional information in error message
This commit is contained in:
Zach Borboa
2016-09-01 00:27:44 -07:00
committed by GitHub
3 changed files with 15 additions and 4 deletions
+3 -3
View File
@@ -70,8 +70,7 @@ $curl->get('https://www.example.com/');
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
}
else {
} else {
echo $curl->response;
}
@@ -149,7 +148,8 @@ $multi_curl = new MultiCurl();
$multi_curl->success(function($instance) {
echo 'call to "' . $instance->url . '" was successful.' . "\n";
echo 'response: ' . $instance->response . "\n";
echo 'response:' . "\n";
var_dump($instance->response);
});
$multi_curl->error(function($instance) {
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
+9 -1
View File
@@ -204,6 +204,7 @@ class Curl
$this->options = null;
$this->jsonDecoder = null;
$this->xmlDecoder = null;
$this->defaultDecoder = null;
}
/**
@@ -340,11 +341,18 @@ class Curl
$this->call($this->beforeSendFunction);
$this->rawResponse = curl_exec($this->curl);
$this->curlErrorCode = curl_errno($this->curl);
$this->curlErrorMessage = curl_error($this->curl);
} else {
$this->rawResponse = curl_multi_getcontent($ch);
$this->curlErrorMessage = curl_error($ch);
}
$this->curlErrorMessage = curl_error($this->curl);
$this->curlError = !($this->curlErrorCode === 0);
// Include additional error code information in error message when possible.
if ($this->curlError && function_exists('curl_strerror')) {
$this->curlErrorMessage = curl_strerror($this->curlErrorCode) . ': ' . $this->curlErrorMessage;
}
$this->httpStatusCode = $this->getInfo(CURLINFO_HTTP_CODE);
$this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5));
$this->error = $this->curlError || $this->httpError;
+3
View File
@@ -536,6 +536,9 @@ class MultiCurl
if ($info_array['msg'] === CURLMSG_DONE) {
foreach ($this->curls as $key => $ch) {
if ($ch->curl === $info_array['handle']) {
// Set the error code for multi handles using the "result" key in the array returned by
// curl_multi_info_read(). Using curl_errno() on a multi handle will incorrectly return 0
// for errors.
$ch->curlErrorCode = $info_array['result'];
$ch->exec($ch->curl);
curl_multi_remove_handle($this->multiCurl, $ch->curl);