fix sse error handling if shop api error part 3

This commit is contained in:
team2
2026-04-25 20:49:45 +02:00
parent 2044a465ad
commit d13e5537ed
6 changed files with 112 additions and 12 deletions

View File

@@ -83,19 +83,32 @@ final readonly class StoreApiClient
{
$preview = mb_substr(trim($content), 0, 1000);
$utf8Failure = $this->containsUtf8FailureSignal($preview);
$serverFailure = $statusCode >= 500;
$normalizedPreview = mb_strtolower($preview, 'UTF-8');
$accessKeyFailure = $statusCode === 401
|| $statusCode === 403
|| str_contains($preview, 'FRAMEWORK__API_INVALID_ACCESS_KEY')
|| str_contains($normalizedPreview, 'access key is invalid');
$serverFailure = $statusCode >= 500 || $accessKeyFailure;
$hint = '';
if ($accessKeyFailure) {
$hint = ' Hint: The configured Shopware Sales Channel access key is invalid or does not match the Store API endpoint.';
} elseif ($utf8Failure) {
$hint = ' Hint: The request body was valid JSON; this Shopware error usually means Shopware failed while encoding response/product data as UTF-8.';
}
return new StoreApiException(
sprintf(
'Shopware Store API request failed with status %d. Response: %s%s',
$statusCode,
$preview,
$utf8Failure ? ' Hint: The request body was valid JSON; this Shopware error usually means Shopware failed while encoding response/product data as UTF-8.' : ''
$hint
),
$statusCode,
$serverFailure,
$utf8Failure,
$serverFailure || $utf8Failure
$serverFailure || $utf8Failure || $accessKeyFailure
);
}