summaryrefslogtreecommitdiffstats
path: root/src/PurpleCode
diff options
context:
space:
mode:
authorMateusz Jaworski <mateusz.jaworski@nokia.com>2015-07-31 09:09:38 +0200
committerMateusz Jaworski <mateusz.jaworski@nokia.com>2015-07-31 09:09:38 +0200
commit7d8941fee6cece66ae3f872beb8f71ddcf4bcb1c (patch)
treed39a341fcd76b5f5d6fc0832bc9504f11c4a6495 /src/PurpleCode
parentfd0f39cb224de007e6135c9e08cc9429c7b5a9dc (diff)
downloadphp.curl-7d8941fee6cece66ae3f872beb8f71ddcf4bcb1c.zip
php.curl-7d8941fee6cece66ae3f872beb8f71ddcf4bcb1c.tar.gz
php.curl-7d8941fee6cece66ae3f872beb8f71ddcf4bcb1c.tar.bz2
curl error code in exception
Diffstat (limited to 'src/PurpleCode')
-rw-r--r--src/PurpleCode/PCurl/PCurl.php5
-rw-r--r--src/PurpleCode/PCurl/PCurlException.php56
2 files changed, 37 insertions, 24 deletions
diff --git a/src/PurpleCode/PCurl/PCurl.php b/src/PurpleCode/PCurl/PCurl.php
index cd442d0..090f8a7 100644
--- a/src/PurpleCode/PCurl/PCurl.php
+++ b/src/PurpleCode/PCurl/PCurl.php
@@ -26,7 +26,7 @@ class PCurl {
public function __construct($host) {
if (!function_exists('curl_init')) {
- throw new PCurlException('CURL module not available! See http://php.net/manual/en/book.curl.php');
+ throw new PCurlException('CURL module not available! See http://php.net/manual/en/book.curl.php', 500, 2 /*CURLE_FAILED_INIT */);
}
$this->host = $host;
@@ -100,8 +100,9 @@ class PCurl {
$response = curl_exec($curl);
if (!$response) {
$error = curl_error($curl);
+ $errorCode = curl_errno($curl);
curl_close($curl);
- throw new PCurlException($error);
+ throw new PCurlException($error, 400, $errorCode);
}
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
diff --git a/src/PurpleCode/PCurl/PCurlException.php b/src/PurpleCode/PCurl/PCurlException.php
index 0e06e6d..ccd9269 100644
--- a/src/PurpleCode/PCurl/PCurlException.php
+++ b/src/PurpleCode/PCurl/PCurlException.php
@@ -11,31 +11,43 @@
namespace PurpleCode\PCurl;
-class PCurlException extends \Exception {
-
- public static function getClassName() {
- return get_called_class();
- }
-
- public static function assert($condition, $message, $arguments = array(), $code = 400) {
- if (!$condition) {
- $arguments = array_map('json_encode', self::ensureArray($arguments));
- $arguments = array_merge(array($message), $arguments);
- $message = call_user_func_array('sprintf', $arguments);
- $class = self::getClassName();
- throw new $class($message, $code);
+class PCurlException extends \Exception
+{
+
+ private $httpCode;
+
+ public static function getClassName()
+ {
+ return get_called_class();
+ }
+
+ public static function assert($condition, $message, $arguments = array(), $code = 400)
+ {
+ if (!$condition) {
+ $arguments = array_map('json_encode', self::ensureArray($arguments));
+ $arguments = array_merge(array($message), $arguments);
+ $message = call_user_func_array('sprintf', $arguments);
+ $class = self::getClassName();
+ throw new $class($message, $code);
+ }
}
- }
- public function __construct($message = "Exception", $code = 400, $previous = null) {
- parent::__construct($message, $code, $previous);
- }
+ private static function ensureArray($item)
+ {
+ if (is_null($item)) {
+ return array();
+ }
+ return is_array($item) ? $item : array($item);
+ }
+
+ public function __construct($message = "Exception", $httpCode = 400, $curlErrorCode = CURLE_OK, $previous = null)
+ {
+ parent::__construct($message, $curlErrorCode, $previous);
+ $this->httpCode = $httpCode;
+ }
- private static function ensureArray($item) {
- if (is_null($item)) {
- return array();
+ public function getHttpCode(){
+ return $this->httpCode;
}
- return is_array($item) ? $item : array($item);
- }
}