optimize error handling if shop api error

This commit is contained in:
team 1
2026-04-25 18:37:29 +02:00
parent b9252202eb
commit 93ff6262cc
3 changed files with 31 additions and 15 deletions

View File

@@ -144,15 +144,21 @@ final readonly class AgentRunner
$commerceHistoryContext
);
$primaryShopSearchHadSystemFailure = $this->shopSearchService->hadLastSearchSystemFailure();
$primaryShopSearchFailureReason = $this->shopSearchService->getLastSearchFailureReason();
if ($primaryShopSearchHadSystemFailure) {
$this->agentLogger->warning('Shop repair skipped after Store API system failure', [
'userId' => $userId,
'commerceIntent' => $commerceIntent,
'shopSearchQuery' => $shopSearchQuery,
'failureReason' => $this->shopSearchService->getLastSearchFailureReason(),
'failureReason' => $primaryShopSearchFailureReason,
]);
yield $this->systemMsg(
$this->buildShopUnavailableMessage($primaryShopSearchFailureReason),
'info'
);
$repairPayload = [
'results' => $primaryShopResults,
'attemptedRepair' => false,
@@ -268,6 +274,7 @@ final readonly class AgentRunner
'usedShopRepair' => $usedShopRepair,
'shopRepairQueries' => $shopRepairQueries,
'primaryShopSearchHadSystemFailure' => $primaryShopSearchHadSystemFailure,
'primaryShopSearchFailureReason' => $primaryShopSearchFailureReason ?? null,
'knowledgeChunkCount' => count($knowledgeChunks),
'knowledgeRetrievalPrompt' => $knowledgeRetrievalPrompt,
'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
{
if (!$this->debug) {