Permalink
Browse files

Process cURL error

  • Loading branch information...
zeleznypa committed Jul 11, 2013
1 parent c1d0235 commit f45df87879e0a445f6df4cb95a8317b0f2f66e4c
Showing with 30 additions and 0 deletions.
  1. +30 −0 Zeleznypa/Curl/Curl.php
@@ -27,6 +27,9 @@ class Curl extends \Zeleznypa\Curl\SimpleCurl
/** @var string $endpoint */
private $endpoint;
/** @var FALSE | array $error */
private $error = FALSE;
/** @var array $info */
private $info;
@@ -194,6 +197,16 @@ public function setEndpoint($endpoint)
return $this;
}
/**
* cURL error getter
* @author Pavel Železný <info@pavelzelezny.cz>
* @return FALSE | array
*/
public function getError()
{
return $this->error;
}
/**
* cURL response info getter
* @author Pavel Železný <info@pavelzelezny.cz>
@@ -356,6 +369,22 @@ protected function getDefaultOptions()
return $options;
}
/**
* Process cURL error
* @author Pavel Železný <info@pavelzelezny.cz>
* @param integer $errorCode
* @param string $errorMessage
* @return \Zeleznypa\Curl\Curl Provides fluent interface
*/
protected function processError($errorCode, $errorMessage)
{
if ($errorCode != 0)
{
$this->error = array('code' => $errorCode, 'message' => $errorMessage);
}
return $this;
}
/**
* Process cURL options
* @author Pavel Železný <info@pavelzelezny.cz>
@@ -376,6 +405,7 @@ protected function processResponse()
{
parent::processResponse();
$this->info = curl_getinfo($this->getHandler());
$this->processError(curl_errno($this->getHandler()), curl_error($this->getHandler()));
return $this;
}

0 comments on commit f45df87

Please sign in to comment.