2d74a4e03470213a6d837172cda06fa08193e0e6
[phorkie.git] / src / phorkie / Database / Adapter / Elasticsearch / HTTPRequest.php
1 <?php
2 namespace phorkie;
3
4 class Database_Adapter_Elasticsearch_HTTPRequest extends \HTTP_Request2
5 {
6     public function send()
7     {
8         $res = parent::send();
9         $mainCode = intval($res->getStatus() / 100);
10         if ($mainCode != 2) {
11             $js = json_decode($res->getBody());
12             if (isset($js->error)) {
13                 $error = $js->error;
14             } else {
15                 $error = $res->getBody();
16             }
17             throw new Exception(
18                 'Error in elasticsearch communication: ' . $error
19             );
20         }
21         return $res;
22     }
23 }
24
25 ?>