ActionException.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Elastica\Exception\Bulk\Response;
  3. use Elastica\Bulk\Response;
  4. use Elastica\Exception\BulkException;
  5. class ActionException extends BulkException
  6. {
  7. /**
  8. * @var \Elastica\Response
  9. */
  10. protected $_response;
  11. /**
  12. * @param \Elastica\Bulk\Response $response
  13. */
  14. public function __construct(Response $response)
  15. {
  16. $this->_response = $response;
  17. parent::__construct($this->getErrorMessage($response));
  18. }
  19. /**
  20. * @return \Elastica\Bulk\Action
  21. */
  22. public function getAction()
  23. {
  24. return $this->getResponse()->getAction();
  25. }
  26. /**
  27. * @return \Elastica\Bulk\Response
  28. */
  29. public function getResponse()
  30. {
  31. return $this->_response;
  32. }
  33. /**
  34. * @param \Elastica\Bulk\Response $response
  35. *
  36. * @return string
  37. */
  38. public function getErrorMessage(Response $response)
  39. {
  40. $error = $response->getError();
  41. $opType = $response->getOpType();
  42. $data = $response->getData();
  43. $path = '';
  44. if (isset($data['_index'])) {
  45. $path .= '/'.$data['_index'];
  46. }
  47. if (isset($data['_type'])) {
  48. $path .= '/'.$data['_type'];
  49. }
  50. if (isset($data['_id'])) {
  51. $path .= '/'.$data['_id'];
  52. }
  53. $message = "$opType: $path caused $error";
  54. return $message;
  55. }
  56. }