Skip to content

Commit

Permalink
Add ForbiddenException (#250)
Browse files Browse the repository at this point in the history
* Add ForbiddenException

* Add ForbiddenException test
  • Loading branch information
tomasDostalDS authored Jul 15, 2024
1 parent 821778d commit 2894be9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/DigiSignClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Exception/ForbiddenException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Exception;

/**
* Represents response with http status 403
*/
final class ForbiddenException extends ClientException
{
}
16 changes: 16 additions & 0 deletions tests/DigiSignClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2894be9

Please sign in to comment.