GuzzleException.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Elastica\Exception\Connection;
  3. use Elastica\Exception\ConnectionException;
  4. use Elastica\Request;
  5. use Elastica\Response;
  6. use GuzzleHttp\Exception\TransferException;
  7. /**
  8. * Transport exception.
  9. *
  10. * @author Milan Magudia <milan@magudia.com>
  11. */
  12. class GuzzleException extends ConnectionException
  13. {
  14. /**
  15. * @var TransferException
  16. */
  17. protected $_guzzleException;
  18. /**
  19. * @param \GuzzleHttp\Exception\TransferException $guzzleException
  20. * @param \Elastica\Request $request
  21. * @param \Elastica\Response $response
  22. */
  23. public function __construct(TransferException $guzzleException, Request $request = null, Response $response = null)
  24. {
  25. $this->_guzzleException = $guzzleException;
  26. $message = $this->getErrorMessage($this->getGuzzleException());
  27. parent::__construct($message, $request, $response);
  28. }
  29. /**
  30. * @param \GuzzleHttp\Exception\TransferException $guzzleException
  31. *
  32. * @return string
  33. */
  34. public function getErrorMessage(TransferException $guzzleException)
  35. {
  36. return $guzzleException->getMessage();
  37. }
  38. /**
  39. * @return TransferException
  40. */
  41. public function getGuzzleException()
  42. {
  43. return $this->_guzzleException;
  44. }
  45. }