From 7b4425b096fa8c18d0db9fd9b1ae96d63ee8af55 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 1 Feb 2016 20:18:59 +0100 Subject: first kinda working version --- src/Elasticsearch/Request.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Elasticsearch/Request.php (limited to 'src/Elasticsearch/Request.php') 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 @@ +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 + ); + } +} + +?> -- cgit v1.2.3