class Database_Adapter_Elasticsearch_HTTPRequest extends \HTTP_Request2
{
+ public $allow404 = false;
+
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
- );
+ if ($mainCode === 2) {
+ return $res;
+ }
+
+ if ($this->allow404 && $res->getStatus() == 404) {
+ return $res;
+ }
+ $js = json_decode($res->getBody());
+ if (isset($js->error)) {
+ $error = $js->error;
+ } else {
+ $error = $res->getBody();
}
- return $res;
+ throw new Exception(
+ 'Error in elasticsearch communication'
+ . '(status code ' . $res->getStatus() . '): '
+ . $error
+ );
}
}
$this->searchInstance . 'repo/_query',
\HTTP_Request2::METHOD_DELETE
);
+ $r->allow404 = true;
$r->setBody(
json_encode(
(object)array(
$this->searchInstance . 'file/_query',
\HTTP_Request2::METHOD_DELETE
);
+ $r->allow404 = true;
$r->setBody(
json_encode(
(object)array(
$this->searchInstance . 'repo/' . $repo->id,
\HTTP_Request2::METHOD_DELETE
);
+ $r->allow404 = true;
$r->send();
$this->deleteRepoFiles($repo);
$this->searchInstance . 'file/_query',
\HTTP_Request2::METHOD_DELETE
);
+ $r->allow404 = true;
$r->setBody(
json_encode(
(object)array(