Skip to content

Commit 957ce4f

Browse files
committed
Catch guzzle exception instead
1 parent 90a7d6d commit 957ce4f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ConnectionRepository.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Aws\ApiGatewayManagementApi\ApiGatewayManagementApiClient;
66
use Aws\ApiGatewayManagementApi\Exception\ApiGatewayManagementApiException;
7+
use GuzzleHttp\Exception\ClientException;
78

89
class ConnectionRepository
910
{
@@ -26,15 +27,15 @@ public function sendMessage(string $connectionId, string $data): void
2627
'ConnectionId' => $connectionId,
2728
'Data' => $data,
2829
]);
29-
} catch (ApiGatewayManagementApiException $e) {
30+
} catch (ClientException $guzzleClientException) {
3031
// GoneException: The connection with the provided id no longer exists.
31-
if ($e->getAwsErrorCode() === 'Gone') {
32+
if ($guzzleClientException->getResponse()->getStatusCode() === 410) {
3233
$this->subscriptionRepository->clearConnection($connectionId);
3334

3435
return;
3536
}
3637

37-
throw $e;
38+
throw $guzzleClientException;
3839
}
3940
}
4041
}

tests/HandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Georgeboot\LaravelEchoApiGateway\ConnectionRepository;
1010
use Georgeboot\LaravelEchoApiGateway\Handler;
1111
use Georgeboot\LaravelEchoApiGateway\SubscriptionRepository;
12+
use GuzzleHttp\Psr7\Response;
1213
use Mockery\Mock;
1314
use Psr\Http\Message\RequestInterface;
1415

@@ -82,7 +83,7 @@
8283
$mock = new MockHandler();
8384

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

8889
/** @var SubscriptionRepository */

0 commit comments

Comments
 (0)