mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-17 08:02:20 +00:00
Added AttachmentNotReadyException (#19)
This commit is contained in:
@@ -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
|
||||
|
||||
+1
-1
@@ -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';
|
||||
|
||||
|
||||
+22
-1
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception thrown when an attachment is not yet ready for use.
|
||||
* This typically occurs when trying to use an attachment that is still being processed.
|
||||
*/
|
||||
class AttachmentNotReadyException extends ClientApiException
|
||||
{
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Client;
|
||||
use BushlanovDev\MaxMessengerBot\Exceptions\AttachmentNotReadyException;
|
||||
use BushlanovDev\MaxMessengerBot\Exceptions\ClientApiException;
|
||||
use BushlanovDev\MaxMessengerBot\Exceptions\ForbiddenException;
|
||||
use BushlanovDev\MaxMessengerBot\Exceptions\MethodNotAllowedException;
|
||||
@@ -242,6 +243,12 @@ final class ClientTest extends TestCase
|
||||
public static function apiErrorProvider(): array
|
||||
{
|
||||
return [
|
||||
'400 Attachment Not Ready' => [
|
||||
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'],
|
||||
|
||||
Reference in New Issue
Block a user