Skip to content

Commit

Permalink
Client: log query on exception then rethrow it (#1920)
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 authored May 13, 2024
1 parent 40467ce commit 86fca8a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Elastica/Client.php
Original file line number Diff line number Diff line change
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 86fca8a

Please sign in to comment.