aboutsummaryrefslogtreecommitdiff
path: root/src/phinde/Elasticsearch/Request.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2016-02-03 06:21:30 +0100
committerChristian Weiske <cweiske@cweiske.de>2016-02-03 06:21:30 +0100
commit226508cd8d3e8c147ad314a0de483e08be71c254 (patch)
tree4142696d28830efa13835be79fd3ee888a4ab0a4 /src/phinde/Elasticsearch/Request.php
parent7b4425b096fa8c18d0db9fd9b1ae96d63ee8af55 (diff)
downloadphinde-226508cd8d3e8c147ad314a0de483e08be71c254.tar.gz
phinde-226508cd8d3e8c147ad314a0de483e08be71c254.zip
first frontend
Diffstat (limited to 'src/phinde/Elasticsearch/Request.php')
-rw-r--r--src/phinde/Elasticsearch/Request.php35
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
+ );
+ }
+}
+
+?>