optimize error handling if shop api error
This commit is contained in:
@@ -144,15 +144,21 @@ final readonly class AgentRunner
|
|||||||
$commerceHistoryContext
|
$commerceHistoryContext
|
||||||
);
|
);
|
||||||
$primaryShopSearchHadSystemFailure = $this->shopSearchService->hadLastSearchSystemFailure();
|
$primaryShopSearchHadSystemFailure = $this->shopSearchService->hadLastSearchSystemFailure();
|
||||||
|
$primaryShopSearchFailureReason = $this->shopSearchService->getLastSearchFailureReason();
|
||||||
|
|
||||||
if ($primaryShopSearchHadSystemFailure) {
|
if ($primaryShopSearchHadSystemFailure) {
|
||||||
$this->agentLogger->warning('Shop repair skipped after Store API system failure', [
|
$this->agentLogger->warning('Shop repair skipped after Store API system failure', [
|
||||||
'userId' => $userId,
|
'userId' => $userId,
|
||||||
'commerceIntent' => $commerceIntent,
|
'commerceIntent' => $commerceIntent,
|
||||||
'shopSearchQuery' => $shopSearchQuery,
|
'shopSearchQuery' => $shopSearchQuery,
|
||||||
'failureReason' => $this->shopSearchService->getLastSearchFailureReason(),
|
'failureReason' => $primaryShopSearchFailureReason,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
yield $this->systemMsg(
|
||||||
|
$this->buildShopUnavailableMessage($primaryShopSearchFailureReason),
|
||||||
|
'info'
|
||||||
|
);
|
||||||
|
|
||||||
$repairPayload = [
|
$repairPayload = [
|
||||||
'results' => $primaryShopResults,
|
'results' => $primaryShopResults,
|
||||||
'attemptedRepair' => false,
|
'attemptedRepair' => false,
|
||||||
@@ -268,6 +274,7 @@ final readonly class AgentRunner
|
|||||||
'usedShopRepair' => $usedShopRepair,
|
'usedShopRepair' => $usedShopRepair,
|
||||||
'shopRepairQueries' => $shopRepairQueries,
|
'shopRepairQueries' => $shopRepairQueries,
|
||||||
'primaryShopSearchHadSystemFailure' => $primaryShopSearchHadSystemFailure,
|
'primaryShopSearchHadSystemFailure' => $primaryShopSearchHadSystemFailure,
|
||||||
|
'primaryShopSearchFailureReason' => $primaryShopSearchFailureReason ?? null,
|
||||||
'knowledgeChunkCount' => count($knowledgeChunks),
|
'knowledgeChunkCount' => count($knowledgeChunks),
|
||||||
'knowledgeRetrievalPrompt' => $knowledgeRetrievalPrompt,
|
'knowledgeRetrievalPrompt' => $knowledgeRetrievalPrompt,
|
||||||
'usedFollowUpRetrievalContext' => $usedFollowUpRetrievalContext,
|
'usedFollowUpRetrievalContext' => $usedFollowUpRetrievalContext,
|
||||||
@@ -783,6 +790,25 @@ final readonly class AgentRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildShopUnavailableMessage(?string $reason): string
|
||||||
|
{
|
||||||
|
$reason = trim((string) $reason);
|
||||||
|
|
||||||
|
if ($reason === '') {
|
||||||
|
$reason = 'keine Detailmeldung vom Shopware-Server';
|
||||||
|
}
|
||||||
|
|
||||||
|
$reason = preg_replace('/\s+/u', ' ', $reason) ?? $reason;
|
||||||
|
|
||||||
|
if (mb_strlen($reason, 'UTF-8') > 260) {
|
||||||
|
$reason = rtrim(mb_substr($reason, 0, 257, 'UTF-8')) . '...';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '⚠️ Shopsystem aktuell nicht erreichbar oder fehlerhaft. Grund: '
|
||||||
|
. htmlspecialchars($reason, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
|
||||||
|
. '. Ich antworte ohne Shopdaten weiter.';
|
||||||
|
}
|
||||||
|
|
||||||
private function buildUserErrorMessage(Throwable $e): string
|
private function buildUserErrorMessage(Throwable $e): string
|
||||||
{
|
{
|
||||||
if (!$this->debug) {
|
if (!$this->debug) {
|
||||||
|
|||||||
@@ -103,13 +103,14 @@ final class ShopSearchService
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($this->lastSearchHadSystemFailure) {
|
if ($this->lastSearchHadSystemFailure) {
|
||||||
$this->logger->warning('Shop search stopped after Store API system failure during reference probe', [
|
$this->logger->warning('Shop search reference probe failed, continuing with primary search', [
|
||||||
'commerceIntent' => $commerceIntent,
|
'commerceIntent' => $commerceIntent,
|
||||||
'originalPrompt' => $originalPrompt,
|
'originalPrompt' => $originalPrompt,
|
||||||
'failureReason' => $this->lastSearchFailureReason,
|
'failureReason' => $this->lastSearchFailureReason,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//return [];
|
// A reference probe is only an enrichment step. It must not block the primary shop search.
|
||||||
|
$this->resetLastSearchFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rankedProducts = $this->executeSearch(
|
$rankedProducts = $this->executeSearch(
|
||||||
@@ -238,17 +239,6 @@ final class ShopSearchService
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->lastSearchHadSystemFailure) {
|
|
||||||
$this->logger->warning('Shop reference probe stopped after Store API system failure', [
|
|
||||||
'commerceIntent' => $commerceIntent,
|
|
||||||
'originalPrompt' => $originalPrompt,
|
|
||||||
'referenceSearchText' => $referenceSearchText,
|
|
||||||
'failureReason' => $this->lastSearchFailureReason,
|
|
||||||
]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($results !== []) {
|
if ($results !== []) {
|
||||||
$allResults = array_merge($allResults, $results);
|
$allResults = array_merge($allResults, $results);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||||||
|
|
||||||
final readonly class AskSseController
|
final readonly class AskSseController
|
||||||
{
|
{
|
||||||
private const JOB_TTL_SECONDS = 30;
|
private const JOB_TTL_SECONDS = 900;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private AgentRunner $agentRunner,
|
private AgentRunner $agentRunner,
|
||||||
|
|||||||
Reference in New Issue
Block a user