From 2b3eca8536ce636699f28a9cfc530fcea3d76b07 Mon Sep 17 00:00:00 2001 From: leob Date: Sun, 8 Dec 2024 00:36:37 +0800 Subject: [PATCH] improve handling of HTTP 410 'Gone' exception --- src/ConnectionRepository.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ConnectionRepository.php b/src/ConnectionRepository.php index 44b0df9..79f795e 100644 --- a/src/ConnectionRepository.php +++ b/src/ConnectionRepository.php @@ -4,6 +4,7 @@ use Aws\ApiGatewayManagementApi\ApiGatewayManagementApiClient; use Aws\ApiGatewayManagementApi\Exception\ApiGatewayManagementApiException; +use Symfony\Component\HttpFoundation\Response; class ConnectionRepository { @@ -30,8 +31,11 @@ public function sendMessage(string $connectionId, string $data): void 'Data' => $data, ]); } catch (ApiGatewayManagementApiException $e) { - // GoneException: The connection with the provided id no longer exists. - if ($e->getAwsErrorCode() === 'GoneException') { + // GoneException: The connection with the provided id no longer exists + if ( + $e->getStatusCode() === Response::HTTP_GONE || + $e->getAwsErrorCode() === 'GoneException' + ) { $this->subscriptionRepository->clearConnection($connectionId); return;