From 4271cdea3722571ef008d680e5873e04775fe66b Mon Sep 17 00:00:00 2001 From: TomasDostal Date: Mon, 15 Jul 2024 07:45:44 +0200 Subject: [PATCH 1/2] Add ForbiddenException --- CHANGELOG.md | 1 + src/DigiSignClient.php | 4 ++++ src/Exception/ForbiddenException.php | 12 ++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 src/Exception/ForbiddenException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cae3a4..d2a28e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## [Unreleased] +- Add `ForbiddenException` - Add `AccountBilling.productType` - Add `EnvelopesEndpoint.cancel` body - Fix `AccountUsersEndpoint.invite` endpoint diff --git a/src/DigiSignClient.php b/src/DigiSignClient.php index f3de10b..b3dfb9d 100644 --- a/src/DigiSignClient.php +++ b/src/DigiSignClient.php @@ -7,6 +7,7 @@ use DateTimeInterface; use DigitalCz\DigiSign\Exception\BadRequestException; use DigitalCz\DigiSign\Exception\ClientException; +use DigitalCz\DigiSign\Exception\ForbiddenException; use DigitalCz\DigiSign\Exception\NotFoundException; use DigitalCz\DigiSign\Exception\RuntimeException; use DigitalCz\DigiSign\Exception\ServerException; @@ -34,6 +35,7 @@ final class DigiSignClient implements DigiSignClientInterface public const HTTP_NO_CONTENT = 204; public const HTTP_BAD_REQUEST = 400; public const HTTP_UNAUTHORIZED = 401; + public const HTTP_FORBIDDEN = 403; public const HTTP_NOT_FOUND = 404; public const HTTP_INTERNAL_SERVER_ERROR = 500; @@ -288,6 +290,8 @@ private function checkResponse(ResponseInterface $response): void throw new UnauthorizedException($response); case self::HTTP_NOT_FOUND: throw new NotFoundException($response); + case self::HTTP_FORBIDDEN: + throw new ForbiddenException($response); default: throw new ClientException($response); } diff --git a/src/Exception/ForbiddenException.php b/src/Exception/ForbiddenException.php new file mode 100644 index 0000000..a9237e5 --- /dev/null +++ b/src/Exception/ForbiddenException.php @@ -0,0 +1,12 @@ + Date: Mon, 15 Jul 2024 13:46:20 +0200 Subject: [PATCH 2/2] Add ForbiddenException test --- tests/DigiSignClientTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/DigiSignClientTest.php b/tests/DigiSignClientTest.php index 45c2f0f..e781e31 100644 --- a/tests/DigiSignClientTest.php +++ b/tests/DigiSignClientTest.php @@ -7,6 +7,7 @@ use DateTime; use DigitalCz\DigiSign\Exception\BadRequestException; use DigitalCz\DigiSign\Exception\ClientException; +use DigitalCz\DigiSign\Exception\ForbiddenException; use DigitalCz\DigiSign\Exception\NotFoundException; use DigitalCz\DigiSign\Exception\RuntimeException; use DigitalCz\DigiSign\Exception\ServerException; @@ -339,6 +340,21 @@ public function testRequestClientException(): void $client->request('GET', 'https://example.com/api'); } + public function testRequestForbiddenClientException(): void + { + $response = new Response(403); + + $httpClient = new Client(); + $httpClient->addResponse($response); + + $client = new DigiSignClient($httpClient); + + $this->expectException(ForbiddenException::class); + $this->expectExceptionMessage('403 Forbidden'); + + $client->request('GET', 'https://example.com/api'); + } + public function testNormalizeJson(): void { $httpClient = new Client();