Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ForbiddenException #250

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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