diff options
Diffstat (limited to 'src/phinde/Elasticsearch/Request.php')
| -rw-r--r-- | src/phinde/Elasticsearch/Request.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/phinde/Elasticsearch/Request.php b/src/phinde/Elasticsearch/Request.php new file mode 100644 index 0000000..7bb6add --- /dev/null +++ b/src/phinde/Elasticsearch/Request.php @@ -0,0 +1,35 @@ +<?php +namespace phinde; + +class Elasticsearch_Request extends \HTTP_Request2 +{ + public $allow404 = false; + + public function send() + { + $res = parent::send(); + $mainCode = intval($res->getStatus() / 100); + if ($mainCode === 2) { + return $res; + } + + if ($this->allow404 && $res->getStatus() == 404) { + return $res; + } + $js = json_decode($res->getBody()); + if (isset($js->error)) { + $error = json_encode($js->error); + } else { + $error = $res->getBody(); + } + + throw new \Exception( + 'Error in elasticsearch communication at ' + . $this->getMethod() . ' ' . (string) $this->getUrl() + . ' (status code ' . $res->getStatus() . '): ' + . $error + ); + } +} + +?> |
