From a7773c0b938772f7d64904442f4375b62122b518 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 6 Dec 2025 15:15:39 +0300 Subject: [PATCH] Added AttachmentNotReadyException (#19) --- .github/workflows/ci.yml | 7 +----- src/Api.php | 2 +- src/Client.php | 23 ++++++++++++++++++- .../AttachmentNotReadyException.php | 13 +++++++++++ tests/ClientTest.php | 7 ++++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 src/Exceptions/AttachmentNotReadyException.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20f5f36..accba3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,12 +44,7 @@ jobs: coverage: xdebug - name: Install composer dependencies - run: | - if [[ "${{ matrix.php-versions }}" == "8.5" ]]; then - composer install --prefer-dist --no-interaction --ignore-platform-req=php - else - composer install --prefer-dist --no-interaction - fi + run: composer install --prefer-dist --no-interaction - name: PHPUnit run: ./vendor/bin/phpunit --configuration=phpunit.xml --coverage-text diff --git a/src/Api.php b/src/Api.php index a49b18d..d943374 100644 --- a/src/Api.php +++ b/src/Api.php @@ -48,7 +48,7 @@ use RuntimeException; */ class Api { - public const string LIBRARY_VERSION = '1.4.1'; + public const string LIBRARY_VERSION = '1.4.2'; public const string API_VERSION = '1.2.5'; diff --git a/src/Client.php b/src/Client.php index 999b889..3caceae 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace BushlanovDev\MaxMessengerBot; +use BushlanovDev\MaxMessengerBot\Exceptions\AttachmentNotReadyException; use BushlanovDev\MaxMessengerBot\Exceptions\ForbiddenException; use BushlanovDev\MaxMessengerBot\Exceptions\ClientApiException; use BushlanovDev\MaxMessengerBot\Exceptions\MethodNotAllowedException; @@ -252,7 +253,27 @@ final readonly class Client implements ClientApiInterface 404 => new NotFoundException($errorMessage, $errorCode, $response), 405 => new MethodNotAllowedException($errorMessage, $errorCode, $response), 429 => new RateLimitExceededException($errorMessage, $errorCode, $response), - default => new ClientApiException($errorMessage, $errorCode, $response, $statusCode), + default => $this->mapErrorCodeToException($errorMessage, $errorCode, $response, $statusCode), + }; + } + + /** + * @param string $message + * @param string $errorCode + * @param ResponseInterface $response + * @param int|null $httpStatusCode + * + * @return ClientApiException + */ + private function mapErrorCodeToException( + string $message, + string $errorCode, + ResponseInterface $response, + ?int $httpStatusCode = null, + ): ClientApiException { + return match ($errorCode) { + 'attachment.not.ready' => new AttachmentNotReadyException($message, $errorCode, $response, $httpStatusCode), + default => new ClientApiException($message, $errorCode, $response, $httpStatusCode), }; } } diff --git a/src/Exceptions/AttachmentNotReadyException.php b/src/Exceptions/AttachmentNotReadyException.php new file mode 100644 index 0000000..6ccf200 --- /dev/null +++ b/src/Exceptions/AttachmentNotReadyException.php @@ -0,0 +1,13 @@ + [ + 400, + AttachmentNotReadyException::class, + 'attachment.not.ready', + 'Key: errors.process.attachment.file.not.processed', + ], '400 Bad Request' => [400, ClientApiException::class, 'bad.request', 'Invalid parameters'], '401 Unauthorized' => [401, UnauthorizedException::class, 'verify.token', 'Invalid access_token'], '403 Forbidden' => [403, ForbiddenException::class, 'access.denied', 'You don\'t have permissions'],