vendor/ruflin/elastica/src/Exception/Connection/HttpException.php line 14

Open in your IDE?
  1. <?php
  2. namespace Elastica\Exception\Connection;
  3. use Elastica\Exception\ConnectionException;
  4. use Elastica\Request;
  5. use Elastica\Response;
  6. /**
  7. * Connection exception.
  8. *
  9. * @author Nicolas Ruflin <spam@ruflin.com>
  10. */
  11. class HttpException extends ConnectionException
  12. {
  13. /**
  14. * Error code / message.
  15. *
  16. * @var int Error code / message
  17. */
  18. protected $_error = 0;
  19. /**
  20. * Construct Exception.
  21. *
  22. * @param int $error
  23. */
  24. public function __construct($error, ?Request $request = null, ?Response $response = null)
  25. {
  26. $this->_error = $error;
  27. $message = $this->getErrorMessage($this->getError());
  28. parent::__construct($message, $request, $response);
  29. }
  30. /**
  31. * Returns the error message corresponding to the error code
  32. * cUrl error code reference can be found here {@link http://curl.haxx.se/libcurl/c/libcurl-errors.html}.
  33. *
  34. * @param int $error Error code
  35. *
  36. * @return string Error message
  37. */
  38. public function getErrorMessage(int $error): string
  39. {
  40. switch ($error) {
  41. case \CURLE_UNSUPPORTED_PROTOCOL:
  42. return 'Unsupported protocol';
  43. case \CURLE_FAILED_INIT:
  44. return 'Internal cUrl error?';
  45. case \CURLE_URL_MALFORMAT:
  46. return 'Malformed URL';
  47. case \CURLE_COULDNT_RESOLVE_PROXY:
  48. return "Couldn't resolve proxy";
  49. case \CURLE_COULDNT_RESOLVE_HOST:
  50. return "Couldn't resolve host";
  51. case \CURLE_COULDNT_CONNECT:
  52. return "Couldn't connect to host, Elasticsearch down?";
  53. case \CURLE_OPERATION_TIMEOUTED:
  54. return 'Operation timed out';
  55. }
  56. return 'Unknown error:'.$error;
  57. }
  58. /**
  59. * Return Error code / message.
  60. *
  61. * @return int Error code / message
  62. */
  63. public function getError(): int
  64. {
  65. return $this->_error;
  66. }
  67. }