From 5bef79679b460cf210a78a35bc79c81ecc4f35fc Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Mon, 26 Feb 2024 13:50:02 +0100 Subject: [PATCH] rename exceptions --- src/Client.php | 4 ++-- src/Endpoint/CategoryEndpoint.php | 12 ++++++------ src/Endpoint/ProductEndpoint.php | 4 ++-- src/Endpoint/TokenEndpoint.php | 4 ++-- ...AlibabaApiException.php => ResponseException.php} | 2 +- ...ltException.php => UnexpectedResultException.php} | 2 +- tests/ClientTest.php | 4 ++-- ...piExceptionTest.php => ResponseExceptionTest.php} | 6 +++--- ...ionTest.php => UnexpectedResultExceptionTest.php} | 6 +++--- 9 files changed, 22 insertions(+), 22 deletions(-) rename src/Exception/{AlibabaApiException.php => ResponseException.php} (92%) rename src/Exception/{UnexpectedApiResultException.php => UnexpectedResultException.php} (83%) rename tests/Exception/{AlibabaApiExceptionTest.php => ResponseExceptionTest.php} (78%) rename tests/Exception/{UnexpectedApiResultExceptionTest.php => UnexpectedResultExceptionTest.php} (69%) diff --git a/src/Client.php b/src/Client.php index 9ce2112..c9048a7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Util\Clock; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -96,7 +96,7 @@ private function throwOnError(array $data): void $errorResponse = $data['error_response'] ?? null; if ($errorResponse !== null) { - throw new AlibabaApiException( + throw new ResponseException( $errorResponse['msg'], (int) $errorResponse['code'], $errorResponse['sub_msg'], diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index 3970b5e..09b33d2 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -5,8 +5,8 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; -use Kyto\Alibaba\Exception\UnexpectedApiResultException; +use Kyto\Alibaba\Exception\ResponseException; +use Kyto\Alibaba\Exception\UnexpectedResultException; use Kyto\Alibaba\Factory\CategoryFactory; use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; @@ -36,7 +36,7 @@ public function __construct( * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=50064 * * @param ?string $id Provide `null` to fetch root categories - * @throws AlibabaApiException + * @throws ResponseException */ public function get(?string $id = null): Category { @@ -55,7 +55,7 @@ public function get(?string $id = null): Category * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=25348 * * @return CategoryAttribute[] - * @throws AlibabaApiException + * @throws ResponseException */ public function getAttributes(string $categoryId): array { @@ -79,7 +79,7 @@ public function getAttributes(string $categoryId): array * @link https://developer.alibaba.com/en/doc.htm?spm=a2728.12183079.k2mwm9fd.1.4b3630901WuQWY#?docType=2&docId=48659 * * @param ?string $valueId provide null to fetch root level - * @throws AlibabaApiException | UnexpectedApiResultException + * @throws ResponseException|UnexpectedResultException */ public function getLevelAttribute( string $categoryId, @@ -105,7 +105,7 @@ public function getLevelAttribute( ); $attribute = $data['alibaba_icbu_category_level_attr_get_response']['result_list'] - ?? throw new UnexpectedApiResultException($errorMessage); + ?? throw new UnexpectedResultException($errorMessage); return $this->categoryFactory->createLevelAttribute($attribute); } diff --git a/src/Endpoint/ProductEndpoint.php b/src/Endpoint/ProductEndpoint.php index 4c41459..e654c32 100644 --- a/src/Endpoint/ProductEndpoint.php +++ b/src/Endpoint/ProductEndpoint.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Factory\ProductFactory; use Kyto\Alibaba\Model\ProductGroup; use Kyto\Alibaba\Model\Token; @@ -34,7 +34,7 @@ public function __construct( * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=25299 * * @param ?string $id Provide `null` to fetch root groups - * @throws AlibabaApiException + * @throws ResponseException */ public function getGroup(Token $token, ?string $id = null): ProductGroup { diff --git a/src/Endpoint/TokenEndpoint.php b/src/Endpoint/TokenEndpoint.php index 03e5f80..04be7e1 100644 --- a/src/Endpoint/TokenEndpoint.php +++ b/src/Endpoint/TokenEndpoint.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Factory\TokenFactory; use Kyto\Alibaba\Model\Token; @@ -33,7 +33,7 @@ public function __construct( * @link https://open.taobao.com/api.htm?spm=a219a.7386653.0.0.41449b714zR8KI&docId=25388&docType=2&source=search * @see \Kyto\Alibaba\Facade::getAuthorizationUrl * - * @throws AlibabaApiException|\JsonException + * @throws ResponseException|\JsonException */ public function new(string $authorizationCode): Token { diff --git a/src/Exception/AlibabaApiException.php b/src/Exception/ResponseException.php similarity index 92% rename from src/Exception/AlibabaApiException.php rename to src/Exception/ResponseException.php index c081e13..b1351c7 100644 --- a/src/Exception/AlibabaApiException.php +++ b/src/Exception/ResponseException.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba\Exception; -class AlibabaApiException extends AlibabaException +class ResponseException extends AlibabaException { /** * @internal diff --git a/src/Exception/UnexpectedApiResultException.php b/src/Exception/UnexpectedResultException.php similarity index 83% rename from src/Exception/UnexpectedApiResultException.php rename to src/Exception/UnexpectedResultException.php index eef1345..4cfb418 100644 --- a/src/Exception/UnexpectedApiResultException.php +++ b/src/Exception/UnexpectedResultException.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba\Exception; -class UnexpectedApiResultException extends AlibabaException +class UnexpectedResultException extends AlibabaException { /** * @internal diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 6d63079..8ed76d1 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Tests; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Util\Clock; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -81,7 +81,7 @@ public function testRequest(bool $isSuccess, array $responseData): void ->willReturn($response); if (!$isSuccess) { - $this->expectException(AlibabaApiException::class); + $this->expectException(ResponseException::class); } $actual = $this->client->request(['hello' => 'world', 'test' => 'data']); diff --git a/tests/Exception/AlibabaApiExceptionTest.php b/tests/Exception/ResponseExceptionTest.php similarity index 78% rename from tests/Exception/AlibabaApiExceptionTest.php rename to tests/Exception/ResponseExceptionTest.php index e2d6949..21f98ec 100644 --- a/tests/Exception/AlibabaApiExceptionTest.php +++ b/tests/Exception/ResponseExceptionTest.php @@ -4,10 +4,10 @@ namespace Kyto\Alibaba\Tests\Exception; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use PHPUnit\Framework\TestCase; -class AlibabaApiExceptionTest extends TestCase +class ResponseExceptionTest extends TestCase { public function testConstruct(): void { @@ -17,7 +17,7 @@ public function testConstruct(): void $subCode = 'sub.code'; $previous = new \RuntimeException('Previous'); - $exception = new AlibabaApiException($message, $code, $subMessage, $subCode, $previous); + $exception = new ResponseException($message, $code, $subMessage, $subCode, $previous); self::assertSame('Message. Sub-code: "sub.code". Sub-message: "Sub-message".', $exception->getMessage()); self::assertSame($code, $exception->getCode()); diff --git a/tests/Exception/UnexpectedApiResultExceptionTest.php b/tests/Exception/UnexpectedResultExceptionTest.php similarity index 69% rename from tests/Exception/UnexpectedApiResultExceptionTest.php rename to tests/Exception/UnexpectedResultExceptionTest.php index cb81635..e3d39d8 100644 --- a/tests/Exception/UnexpectedApiResultExceptionTest.php +++ b/tests/Exception/UnexpectedResultExceptionTest.php @@ -4,10 +4,10 @@ namespace Kyto\Alibaba\Tests\Exception; -use Kyto\Alibaba\Exception\UnexpectedApiResultException; +use Kyto\Alibaba\Exception\UnexpectedResultException; use PHPUnit\Framework\TestCase; -class UnexpectedApiResultExceptionTest extends TestCase +class UnexpectedResultExceptionTest extends TestCase { public function testConstruct(): void { @@ -15,7 +15,7 @@ public function testConstruct(): void $code = 1; $previous = new \RuntimeException('Previous'); - $exception = new UnexpectedApiResultException($message, $code, $previous); + $exception = new UnexpectedResultException($message, $code, $previous); self::assertSame('Message', $exception->getMessage()); self::assertSame($code, $exception->getCode());