Hide exceptions if elasticsearch is not running. This needs some fixing and cleaning up by someone smarter than myself.

This commit is contained in:
Jay Severson 2011-11-09 11:37:28 -08:00
parent 8a9dc124ec
commit eb1900265f

View file

@ -20,7 +20,14 @@ class Client extends Elastica_Client
public function request($path, $method, $data = array())
{
$start = microtime(true);
$response = parent::request($path, $method, $data);
//this is ghetto, but i couldnt figure out another way of making our site continue to behave normally even if ES was not running.
//Any improvements on this welcome. Perhaps another parameter that allows you to control if you want to ignore exceptions about ES not running
try {
$response = parent::request($path, $method, $data);
} catch(\Exception $e) {
//again, ghetto, but couldnt figure out how to return a default empty Elastica_Response
return new \Elastica_Response('{"took":0,"timed_out":false,"hits":{"total":0,"max_score":0,"hits":[]}}');
}
if (null !== $this->logger) {
$time = microtime(true) - $start;