Skip to content

Commit

Permalink
Merge branch '2.11.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Oct 22, 2024
2 parents 7e91626 + c2c2ce5 commit a7055ec
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/module-elasticsuite-core/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Smile\ElasticsuiteCore\Client;

use OpenSearch\Common\Exceptions\Missing404Exception;
use Psr\Log\LoggerInterface;
use Smile\ElasticsuiteCore\Api\Client\ClientConfigurationInterface;
use Smile\ElasticsuiteCore\Api\Client\ClientInterface;

Expand Down Expand Up @@ -44,16 +45,26 @@ class Client implements ClientInterface
*/
private $clientBuilder;

/**
* @var LoggerInterface
*/
private $logger;

/**
* Constructor.
*
* @param ClientConfigurationInterface $clientConfiguration Client configuration factory.
* @param ClientBuilder $clientBuilder ES client builder.
* @param LoggerInterface $logger Logger.
*/
public function __construct(ClientConfigurationInterface $clientConfiguration, ClientBuilder $clientBuilder)
{
public function __construct(
ClientConfigurationInterface $clientConfiguration,
ClientBuilder $clientBuilder,
LoggerInterface $logger
) {
$this->clientConfiguration = $clientConfiguration;
$this->clientBuilder = $clientBuilder;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -201,10 +212,23 @@ public function bulk($bulkParams)

/**
* {@inheritDoc}
* @throws \Exception
*/
public function search($params)
{
return $this->getEsClient()->search($params);
try {
$response = $this->getEsClient()->search($params);
} catch (\Exception $e) {
// If debug is enabled, no need to log, the ES client would already have done it.
if (false === $this->clientConfiguration->isDebugModeEnabled()) {
$requestInfo = json_encode($params, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE);
$this->logger->error(sprintf("Search Request Failure [error] : %s", $e->getMessage()));
$this->logger->error(sprintf("Search Request Failure [request] : %s", $requestInfo));
}
throw $e;
}

return $response;
}

/**
Expand Down

0 comments on commit a7055ec

Please sign in to comment.