Skip to content

Commit

Permalink
Client: log query on exception then rethrow it
Browse files Browse the repository at this point in the history
If an Elastica exception was thrown upon request, then make the request
visible that caused it (on verbose console or in your logs), then
rethrow the exception.
  • Loading branch information
7ochem committed Apr 18, 2024
1 parent 40467ce commit a4d778d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Elastica/Client.php
Expand Up @@ -13,6 +13,7 @@

use Elastica\Client as BaseClient;
use Elastica\Exception\ClientException;
use Elastica\Exception\ExceptionInterface;
use Elastica\Index as BaseIndex;
use Elastica\Request;
use Elastica\Response;
Expand Down Expand Up @@ -58,7 +59,13 @@ public function request(string $path, string $method = Request::GET, $data = [],
$this->stopwatch->start('es_request', 'fos_elastica');
}

$response = parent::request($path, $method, $data, $query, $contentType);
try {
$response = parent::request($path, $method, $data, $query, $contentType);
} catch (ExceptionInterface $e) {
$this->logQuery($path, $method, $data, $query, 0, 0, 0);
throw $e;
}

$responseData = $response->getData();

$transportInfo = $response->getTransferInfo();
Expand Down

0 comments on commit a4d778d

Please sign in to comment.