fix sse error handling if shop api error part 1
This commit is contained in:
@@ -383,6 +383,18 @@ final class ShopSearchService
|
||||
if ($safeResults !== null) {
|
||||
return $safeResults;
|
||||
}
|
||||
|
||||
$minimalResults = $this->retryWithMinimalCriteria(
|
||||
query: $query,
|
||||
commerceIntent: $commerceIntent,
|
||||
originalPrompt: $originalPrompt,
|
||||
usesHistoryContext: $usesHistoryContext,
|
||||
previousException: $e
|
||||
);
|
||||
|
||||
if ($minimalResults !== null) {
|
||||
return $minimalResults;
|
||||
}
|
||||
}
|
||||
|
||||
$this->recordFailedSearch($e);
|
||||
@@ -458,6 +470,61 @@ final class ShopSearchService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ShopProductResult[]|null
|
||||
*/
|
||||
private function retryWithMinimalCriteria(
|
||||
CommerceSearchQuery $query,
|
||||
string $commerceIntent,
|
||||
string $originalPrompt,
|
||||
bool $usesHistoryContext,
|
||||
StoreApiException $previousException
|
||||
): ?array {
|
||||
$this->logger->warning('Shop search retrying with minimal UTF-8-safe criteria', [
|
||||
'commerceIntent' => $commerceIntent,
|
||||
'originalPrompt' => $originalPrompt,
|
||||
'normalizedPrompt' => $query->normalizedPrompt,
|
||||
'searchText' => $query->searchText,
|
||||
'usesHistoryContext' => $usesHistoryContext,
|
||||
'previousStatusCode' => $previousException->getStatusCode(),
|
||||
'previousUtf8Failure' => $previousException->isUtf8Failure(),
|
||||
'previousExceptionMessage' => $previousException->getMessage(),
|
||||
]);
|
||||
|
||||
try {
|
||||
$minimalCriteria = $this->criteriaBuilder->buildMinimal($query, $this->maxResults);
|
||||
$response = $this->storeApiClient->searchProducts($minimalCriteria);
|
||||
|
||||
return $this->mapAndLogSearchResponse(
|
||||
response: $response,
|
||||
query: $query,
|
||||
commerceIntent: $commerceIntent,
|
||||
originalPrompt: $originalPrompt,
|
||||
usesHistoryContext: $usesHistoryContext,
|
||||
usedSafeCriteria: true
|
||||
);
|
||||
} catch (
|
||||
ClientExceptionInterface |
|
||||
RedirectionExceptionInterface |
|
||||
ServerExceptionInterface |
|
||||
TransportExceptionInterface |
|
||||
\RuntimeException $minimalException
|
||||
) {
|
||||
$this->recordFailedSearch($minimalException);
|
||||
$this->logger->warning('Shop search minimal UTF-8-safe criteria retry failed', [
|
||||
'commerceIntent' => $commerceIntent,
|
||||
'originalPrompt' => $originalPrompt,
|
||||
'normalizedPrompt' => $query->normalizedPrompt,
|
||||
'searchText' => $query->searchText,
|
||||
'usesHistoryContext' => $usesHistoryContext,
|
||||
'exceptionClass' => $minimalException::class,
|
||||
'exceptionMessage' => $minimalException->getMessage(),
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $response
|
||||
* @return ShopProductResult[]
|
||||
|
||||
Reference in New Issue
Block a user