Skip to content

Commit

Permalink
Catch guzzle exception instead
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeboot committed Aug 6, 2021
1 parent 90a7d6d commit 957ce4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/ConnectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\ApiGatewayManagementApi\ApiGatewayManagementApiClient;
use Aws\ApiGatewayManagementApi\Exception\ApiGatewayManagementApiException;
use GuzzleHttp\Exception\ClientException;

class ConnectionRepository
{
Expand All @@ -26,15 +27,15 @@ public function sendMessage(string $connectionId, string $data): void
'ConnectionId' => $connectionId,
'Data' => $data,
]);
} catch (ApiGatewayManagementApiException $e) {
} catch (ClientException $guzzleClientException) {
// GoneException: The connection with the provided id no longer exists.
if ($e->getAwsErrorCode() === 'Gone') {
if ($guzzleClientException->getResponse()->getStatusCode() === 410) {
$this->subscriptionRepository->clearConnection($connectionId);

return;
}

throw $e;
throw $guzzleClientException;
}
}
}
3 changes: 2 additions & 1 deletion tests/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Georgeboot\LaravelEchoApiGateway\ConnectionRepository;
use Georgeboot\LaravelEchoApiGateway\Handler;
use Georgeboot\LaravelEchoApiGateway\SubscriptionRepository;
use GuzzleHttp\Psr7\Response;
use Mockery\Mock;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -82,7 +83,7 @@
$mock = new MockHandler();

$mock->append(function (CommandInterface $cmd, RequestInterface $req) {
return new ApiGatewayManagementApiException('', $cmd, ['code' => 'Gone']);
return new \GuzzleHttp\Exception\ClientException('', $req, new Response(410));
});

/** @var SubscriptionRepository */
Expand Down

0 comments on commit 957ce4f

Please sign in to comment.