Skip to content

Commit

Permalink
rename exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik-Czulak committed Feb 26, 2024
1 parent b2a0378 commit 5bef796
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'],
Expand Down
12 changes: 6 additions & 6 deletions src/Endpoint/CategoryEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Endpoint/ProductEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Endpoint/TokenEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kyto\Alibaba\Exception;

class AlibabaApiException extends AlibabaException
class ResponseException extends AlibabaException
{
/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Kyto\Alibaba\Exception;

class UnexpectedApiResultException extends AlibabaException
class UnexpectedResultException extends AlibabaException
{
/**
* @internal
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

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
{
$message = 'Message';
$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());
Expand Down

0 comments on commit 5bef796

Please sign in to comment.