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) {

View File

@@ -103,13 +103,14 @@ final class ShopSearchService
);
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,
'originalPrompt' => $originalPrompt,
'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(
@@ -238,17 +239,6 @@ final class ShopSearchService
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 !== []) {
$allResults = array_merge($allResults, $results);
}

View File

@@ -14,7 +14,7 @@ use Symfony\Component\Routing\Annotation\Route;
final readonly class AskSseController
{
private const JOB_TTL_SECONDS = 30;
private const JOB_TTL_SECONDS = 900;
public function __construct(
private AgentRunner $agentRunner,