logAndThrowException example



        $search = $this->convertSearch($criteria$definition$context$search);

        try {
            $result = $this->client->search([
                'index' => $this->helper->getIndexName($definition$this->helper->enabledMultilingualIndex() ? null : $context->getLanguageId()),
                'track_total_hits' => true,
                'body' => $search,
            ]);
        } catch (\Throwable $e) {
            $this->helper->logAndThrowException($e);

            return $this->decorated->search($definition$criteria$context);
        }

        $result = $this->hydrator->hydrate($definition$criteria$context$result);

        $result->addState(self::RESULT_STATE);

        return $result;
    }

    


        $searchArray = $search->toArray();
        $searchArray['timeout'] = $this->timeout;

        try {
            $result = $this->client->search([
                'index' => $this->helper->getIndexName($definition$this->helper->enabledMultilingualIndex() ? null : $context->getLanguageId()),
                'body' => $searchArray,
            ]);
        } catch (\Throwable $e) {
            $this->helper->logAndThrowException($e);

            return $this->decorated->aggregate($definition$criteria$context);
        }

        $result = $this->hydrator->hydrate($definition$criteria$context$result);
        $result->addState(self::RESULT_STATE);

        return $result;
    }

    private function createSearch(EntityDefinition $definition, Criteria $criteria, Context $context): Search
    {
'prefix',
            true,
            $this->createMock(Client::class),
            $this->createMock(ElasticsearchRegistry::class),
            $this->createMock(CriteriaParser::class),
            $logger,
            $this->createMock(AbstractKeyValueStorage::class)
        );

        static::expectException(\RuntimeException::class);

        static::assertFalse($helper->logAndThrowException(new \RuntimeException('test')));
    }

    public function testLogAndThrowExceptionOnlyLogs(): void
    {
        $logger = $this->createMock(LoggerInterface::class);
        $logger->expects(static::once())->method('critical');
        $helper = new ElasticsearchHelper(
            'prod',
            true,
            true,
            'prefix',
            
private readonly AbstractKeyValueStorage $keyValueStorage
    ) {
        parent::__construct($scheduledTaskRepository);
    }

    public function run(): void
    {
        try {
            $this->handleQueue();
        } catch (\Throwable $e) {
            // catch exception - otherwise the task will never be called again             $this->elasticsearchHelper->logAndThrowException($e);
        }
    }

    private function createAlias(string $index, string $alias): void
    {
        $exist = $this->client->indices()->existsAlias(['name' => $alias]);

        if (!$exist) {
            $this->client->indices()->refresh([
                'index' => $index,
            ]);
            
return $this->prefix . '_' . $definition->getEntityName() . '_' . $languageId;
    }

    public function allowIndexing(): bool
    {
        if (!$this->indexingEnabled) {
            return false;
        }

        if (!$this->client->ping()) {
            return $this->logAndThrowException(new ServerNotAvailableException());
        }

        return true;
    }

    /** * Validates if it is allowed do execute the search request over elasticsearch */
    public function allowSearch(EntityDefinition $definition, Context $context, Criteria $criteria): bool
    {
        if (!$this->searchEnabled) {
            
Home | Imprint | This part of the site doesn't use cookies.