From 6906b04b669e5447552264871a030103d81c550a Mon Sep 17 00:00:00 2001 From: Jochem Klaver Date: Fri, 4 Aug 2023 14:06:24 +0200 Subject: [PATCH] Client: log query on exception then rethrow it 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. --- src/Elastica/Client.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Elastica/Client.php b/src/Elastica/Client.php index e1808949f..587bdcff6 100644 --- a/src/Elastica/Client.php +++ b/src/Elastica/Client.php @@ -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; @@ -60,7 +61,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();