diff options
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Exception/ResponseException.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Exception/ResponseException.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Exception/ResponseException.php b/vendor/ruflin/elastica/lib/Elastica/Exception/ResponseException.php new file mode 100644 index 00000000..57502307 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Exception/ResponseException.php @@ -0,0 +1,70 @@ +<?php +namespace Elastica\Exception; + +use Elastica\Request; +use Elastica\Response; + +/** + * Response exception. + * + * @author Nicolas Ruflin <spam@ruflin.com> + */ +class ResponseException extends \RuntimeException implements ExceptionInterface +{ + /** + * @var \Elastica\Request Request object + */ + protected $_request = null; + + /** + * @var \Elastica\Response Response object + */ + protected $_response = null; + + /** + * Construct Exception. + * + * @param \Elastica\Request $request + * @param \Elastica\Response $response + */ + public function __construct(Request $request, Response $response) + { + $this->_request = $request; + $this->_response = $response; + parent::__construct($response->getError()); + } + + /** + * Returns request object. + * + * @return \Elastica\Request Request object + */ + public function getRequest() + { + return $this->_request; + } + + /** + * Returns response object. + * + * @return \Elastica\Response Response object + */ + public function getResponse() + { + return $this->_response; + } + + /** + * Returns elasticsearch exception. + * + * @return ElasticsearchException + */ + public function getElasticsearchException() + { + $response = $this->getResponse(); + $transfer = $response->getTransferInfo(); + $code = array_key_exists('http_code', $transfer) ? $transfer['http_code'] : 0; + + return new ElasticsearchException($code, $response->getError()); + } +} |