summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Exception/Connection
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Exception/Connection')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Connection/GuzzleException.php50
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Connection/HttpException.php86
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Connection/MemcacheException.php13
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Exception/Connection/ThriftException.php49
4 files changed, 198 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/GuzzleException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/GuzzleException.php
new file mode 100644
index 00000000..614ad139
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/GuzzleException.php
@@ -0,0 +1,50 @@
+<?php
+namespace Elastica\Exception\Connection;
+
+use Elastica\Exception\ConnectionException;
+use Elastica\Request;
+use Elastica\Response;
+use GuzzleHttp\Exception\TransferException;
+
+/**
+ * Transport exception.
+ *
+ * @author Milan Magudia <milan@magudia.com>
+ */
+class GuzzleException extends ConnectionException
+{
+ /**
+ * @var TransferException
+ */
+ protected $_guzzleException;
+
+ /**
+ * @param \GuzzleHttp\Exception\TransferException $guzzleException
+ * @param \Elastica\Request $request
+ * @param \Elastica\Response $response
+ */
+ public function __construct(TransferException $guzzleException, Request $request = null, Response $response = null)
+ {
+ $this->_guzzleException = $guzzleException;
+ $message = $this->getErrorMessage($this->getGuzzleException());
+ parent::__construct($message, $request, $response);
+ }
+
+ /**
+ * @param \GuzzleHttp\Exception\TransferException $guzzleException
+ *
+ * @return string
+ */
+ public function getErrorMessage(TransferException $guzzleException)
+ {
+ return $guzzleException->getMessage();
+ }
+
+ /**
+ * @return TransferException
+ */
+ public function getGuzzleException()
+ {
+ return $this->_guzzleException;
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/HttpException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/HttpException.php
new file mode 100644
index 00000000..28e78e77
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/HttpException.php
@@ -0,0 +1,86 @@
+<?php
+namespace Elastica\Exception\Connection;
+
+use Elastica\Exception\ConnectionException;
+use Elastica\Request;
+use Elastica\Response;
+
+/**
+ * Connection exception.
+ *
+ * @author Nicolas Ruflin <spam@ruflin.com>
+ */
+class HttpException extends ConnectionException
+{
+ /**
+ * Error code / message.
+ *
+ * @var string Error code / message
+ */
+ protected $_error = 0;
+
+ /**
+ * Construct Exception.
+ *
+ * @param string $error Error
+ * @param \Elastica\Request $request
+ * @param \Elastica\Response $response
+ */
+ public function __construct($error, Request $request = null, Response $response = null)
+ {
+ $this->_error = $error;
+
+ $message = $this->getErrorMessage($this->getError());
+ parent::__construct($message, $request, $response);
+ }
+
+ /**
+ * Returns the error message corresponding to the error code
+ * cUrl error code reference can be found here {@link http://curl.haxx.se/libcurl/c/libcurl-errors.html}.
+ *
+ * @param string $error Error code
+ *
+ * @return string Error message
+ */
+ public function getErrorMessage($error)
+ {
+ switch ($error) {
+ case CURLE_UNSUPPORTED_PROTOCOL:
+ $error = 'Unsupported protocol';
+ break;
+ case CURLE_FAILED_INIT:
+ $error = 'Internal cUrl error?';
+ break;
+ case CURLE_URL_MALFORMAT:
+ $error = 'Malformed URL';
+ break;
+ case CURLE_COULDNT_RESOLVE_PROXY:
+ $error = "Couldn't resolve proxy";
+ break;
+ case CURLE_COULDNT_RESOLVE_HOST:
+ $error = "Couldn't resolve host";
+ break;
+ case CURLE_COULDNT_CONNECT:
+ $error = "Couldn't connect to host, Elasticsearch down?";
+ break;
+ case 28:
+ $error = 'Operation timed out';
+ break;
+ default:
+ $error = 'Unknown error:'.$error;
+ break;
+ }
+
+ return $error;
+ }
+
+ /**
+ * Return Error code / message.
+ *
+ * @return string Error code / message
+ */
+ public function getError()
+ {
+ return $this->_error;
+ }
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/MemcacheException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/MemcacheException.php
new file mode 100644
index 00000000..24181379
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/MemcacheException.php
@@ -0,0 +1,13 @@
+<?php
+namespace Elastica\Exception\Connection;
+
+use Elastica\Exception\ConnectionException;
+
+/**
+ * Transport exception.
+ *
+ * @author Igor Denisenko <im.denisenko@yahoo.com>
+ */
+class MemcacheException extends ConnectionException
+{
+}
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/ThriftException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/ThriftException.php
new file mode 100644
index 00000000..499cbd7d
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Exception/Connection/ThriftException.php
@@ -0,0 +1,49 @@
+<?php
+namespace Elastica\Exception\Connection;
+
+use Elastica\Exception\ConnectionException;
+use Elastica\Request;
+use Elastica\Response;
+use Thrift\Exception\TException;
+
+/**
+ * Transport exception.
+ *
+ * @author Mikhail Shamin <munk13@gmail.com>
+ */
+class ThriftException extends ConnectionException
+{
+ /**
+ * @var TException
+ */
+ protected $_thriftException;
+
+ /**
+ * @param \Thrift\Exception\TException $thriftException
+ * @param \Elastica\Request $request
+ * @param \Elastica\Response $response
+ */
+ public function __construct(TException $thriftException, Request $request = null, Response $response = null)
+ {
+ $this->_thriftException = $thriftException;
+ $message = $this->getErrorMessage($this->getThriftException());
+ parent::__construct($message, $request, $response);
+ }
+
+ /**
+ * @param \Thrift\Exception\TException $thriftException
+ *
+ * @return string
+ */
+ public function getErrorMessage(TException $thriftException)
+ {
+ return $thriftException->getMessage();
+ }
+ /**
+ * @return TException
+ */
+ public function getThriftException()
+ {
+ return $this->_thriftException;
+ }
+}