diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2016-02-01 20:18:59 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2016-02-01 20:18:59 +0100 |
| commit | 7b4425b096fa8c18d0db9fd9b1ae96d63ee8af55 (patch) | |
| tree | 2dc5d998a1fd0238592b451ff88b5c4cec064f9b /src/Elasticsearch/Request.php | |
| download | phinde-7b4425b096fa8c18d0db9fd9b1ae96d63ee8af55.tar.gz phinde-7b4425b096fa8c18d0db9fd9b1ae96d63ee8af55.zip | |
first kinda working version
Diffstat (limited to 'src/Elasticsearch/Request.php')
| -rw-r--r-- | src/Elasticsearch/Request.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Elasticsearch/Request.php b/src/Elasticsearch/Request.php new file mode 100644 index 0000000..7bb6add --- /dev/null +++ b/src/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 + ); + } +} + +?> |
