Skip to content

Commit 92a6260

Browse files
committed
ACP2E-3892: [Mainline] Unpopulated pages are cached due to search engine errors
1 parent c79aa3b commit 92a6260

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

app/code/Magento/OpenSearch/SearchAdapter/Adapter.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
use Magento\Elasticsearch\SearchAdapter\ConnectionManager;
1313
use Magento\Elasticsearch\SearchAdapter\QueryContainerFactory;
1414
use Magento\Elasticsearch\SearchAdapter\ResponseFactory;
15+
use Magento\Framework\Phrase;
1516
use Magento\Framework\Search\AdapterInterface;
17+
use Magento\Framework\Search\Request\EmptyRequestDataException;
1618
use Magento\Framework\Search\RequestInterface;
1719
use Magento\Framework\Search\Response\QueryResponse;
1820
use Magento\Search\Model\Search\PageSizeProvider;
21+
use OpenSearch\Common\Exceptions\BadRequest400Exception;
1922
use OpenSearch\Common\Exceptions\Missing404Exception;
2023
use Psr\Log\LoggerInterface;
2124

@@ -46,23 +49,6 @@ class Adapter implements AdapterInterface
4649
*/
4750
private AggregationBuilder $aggregationBuilder;
4851

49-
/**
50-
* Empty response from OpenSearch
51-
*
52-
* @var array
53-
*/
54-
private static $emptyRawResponse = [
55-
'hits' => [
56-
'hits' => []
57-
],
58-
'aggregations' => [
59-
'price_bucket' => [],
60-
'category_bucket' => [
61-
'buckets' => []
62-
]
63-
]
64-
];
65-
6652
/**
6753
* @var QueryContainerFactory
6854
*/
@@ -144,9 +130,11 @@ public function query(RequestInterface $request) : QueryResponse
144130
}
145131

146132
$rawResponse = $client->query($query);
147-
} catch (Missing404Exception $e) {
133+
} catch (Missing404Exception|BadRequest400Exception $e) {
148134
$this->logger->critical($e);
149-
$rawResponse = self::$emptyRawResponse;
135+
throw new EmptyRequestDataException(
136+
(new Phrase("Could not perform search query."))->render()
137+
);
150138
} catch (\Exception $e) {
151139
$this->logger->critical($e);
152140
throw new ClientException($e->getMessage(), $e->getCode(), $e);

app/code/Magento/OpenSearch/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
"OpenSearch HTTP Username","OpenSearch HTTP Username"
88
"OpenSearch HTTP Password","OpenSearch HTTP Password"
99
"OpenSearch Server Timeout","OpenSearch Server Timeout"
10+
"Could not perform search query.","Could not perform search query."

0 commit comments

Comments
 (0)