Skip to content

Commit

Permalink
rename error to exception, add throws tags for public endpoint functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik-Czulak committed Feb 23, 2024
1 parent a80b62c commit b2a0378
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 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\AlibabaApiError;
use Kyto\Alibaba\Exception\AlibabaApiException;
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 AlibabaApiError(
throw new AlibabaApiException(
$errorResponse['msg'],
(int) $errorResponse['code'],
$errorResponse['sub_msg'],
Expand Down
6 changes: 5 additions & 1 deletion src/Endpoint/CategoryEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kyto\Alibaba\Endpoint;

use Kyto\Alibaba\Client;
use Kyto\Alibaba\Exception\AlibabaApiException;
use Kyto\Alibaba\Exception\UnexpectedApiResultException;
use Kyto\Alibaba\Factory\CategoryFactory;
use Kyto\Alibaba\Model\Category;
Expand Down Expand Up @@ -35,6 +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
*/
public function get(?string $id = null): Category
{
Expand All @@ -53,6 +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
*/
public function getAttributes(string $categoryId): array
{
Expand All @@ -75,7 +78,8 @@ public function getAttributes(string $categoryId): array
* Get next-level attribute based on category, attribute and optionally level attribute value ID.
* @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 first level
* @param ?string $valueId provide null to fetch root level
* @throws AlibabaApiException | UnexpectedApiResultException
*/
public function getLevelAttribute(
string $categoryId,
Expand Down
2 changes: 2 additions & 0 deletions src/Endpoint/ProductEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kyto\Alibaba\Endpoint;

use Kyto\Alibaba\Client;
use Kyto\Alibaba\Exception\AlibabaApiException;
use Kyto\Alibaba\Factory\ProductFactory;
use Kyto\Alibaba\Model\ProductGroup;
use Kyto\Alibaba\Model\Token;
Expand Down Expand Up @@ -33,6 +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
*/
public function getGroup(Token $token, ?string $id = null): ProductGroup
{
Expand Down
3 changes: 3 additions & 0 deletions src/Endpoint/TokenEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kyto\Alibaba\Endpoint;

use Kyto\Alibaba\Client;
use Kyto\Alibaba\Exception\AlibabaApiException;
use Kyto\Alibaba\Factory\TokenFactory;
use Kyto\Alibaba\Model\Token;

Expand All @@ -31,6 +32,8 @@ public function __construct(
* To obtain authorization code see corresponding facade method.
* @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
*/
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 AlibabaApiError extends AlibabaException
class AlibabaApiException 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\AlibabaApiError;
use Kyto\Alibaba\Exception\AlibabaApiException;
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(AlibabaApiError::class);
$this->expectException(AlibabaApiException::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\AlibabaApiError;
use Kyto\Alibaba\Exception\AlibabaApiException;
use PHPUnit\Framework\TestCase;

class AlibabaApiErrorTest extends TestCase
class AlibabaApiExceptionTest 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 AlibabaApiError($message, $code, $subMessage, $subCode, $previous);
$exception = new AlibabaApiException($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

0 comments on commit b2a0378

Please sign in to comment.