From 86fca8afd767c132e5011ff5d9cc7c434c5347f3 Mon Sep 17 00:00:00 2001 From: Jochem Klaver <7ochem@users.noreply.github.com> Date: Mon, 13 May 2024 09:55:00 +0200 Subject: [PATCH] Client: log query on exception then rethrow it (#1920) 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 c411834f7..85ece7b96 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; @@ -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();