fix sse error handling if shop api error part 3
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ final class StoreApiException extends RuntimeException
|
||||
|
||||
public function isSystemFailure(): bool
|
||||
{
|
||||
return $this->serverFailure || $this->utf8Failure;
|
||||
if ($this->serverFailure || $this->utf8Failure) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->statusCode === 401 || $this->statusCode === 403;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user