aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-05-07 20:36:13 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-05-07 20:36:13 +0200
commit3c83676016bce1727f0046f4aad7865be8a71fd4 (patch)
tree28a95cdfa56776e454b42ba3126ab54db9806b49 /src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php
parent637ede8759615e1aac86af232f5c053389eb37b7 (diff)
downloadphorkie-3c83676016bce1727f0046f4aad7865be8a71fd4.tar.gz
phorkie-3c83676016bce1727f0046f4aad7865be8a71fd4.zip
use httprequest wrapper to automatically check for errors
Diffstat (limited to 'src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php')
-rw-r--r--src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php
new file mode 100644
index 0000000..2d74a4e
--- /dev/null
+++ b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php
@@ -0,0 +1,25 @@
+<?php
+namespace phorkie;
+
+class Database_Adapter_Elasticsearch_HTTPRequest extends \HTTP_Request2
+{
+ public function send()
+ {
+ $res = parent::send();
+ $mainCode = intval($res->getStatus() / 100);
+ if ($mainCode != 2) {
+ $js = json_decode($res->getBody());
+ if (isset($js->error)) {
+ $error = $js->error;
+ } else {
+ $error = $res->getBody();
+ }
+ throw new Exception(
+ 'Error in elasticsearch communication: ' . $error
+ );
+ }
+ return $res;
+ }
+}
+
+?>