diff --git a/src/Module/Repository/Internal/GitHub/Api/Client.php b/src/Module/Repository/Internal/GitHub/Api/Client.php index be31469..2acacfd 100644 --- a/src/Module/Repository/Internal/GitHub/Api/Client.php +++ b/src/Module/Repository/Internal/GitHub/Api/Client.php @@ -86,9 +86,9 @@ private function checkForRateLimit(ResponseInterface $response): void // GitHub rate limit responses have format: ["API rate limit ...", "https://docs.github.com/..."] if (\is_array($decoded) && \count($decoded) === 2 - && \is_string($decoded[0]) - && \is_string($decoded[1]) - && \str_contains($decoded[0], 'API rate limit') + && \is_string(\reset($decoded)) + && \is_string(\next($decoded)) + && \str_contains(\reset($decoded), 'API rate limit') ) { throw GitHubRateLimitException::fromApiResponse($decoded); } diff --git a/src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php b/src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php index 0cee531..31f47cc 100644 --- a/src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php +++ b/src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php @@ -14,7 +14,7 @@ final class GitHubRateLimitException extends \RuntimeException { public function __construct( public readonly string $documentationUrl, - string $message = 'GitHub API rate limit exceeded', + string $message = 'GitHub API rate limit exceeded. Check the GitHub Token or try again later.', ?\Throwable $previous = null, ) { parent::__construct($message, 0, $previous); @@ -23,13 +23,13 @@ public function __construct( /** * Creates exception from GitHub API response body. * - * @param array{0: string, 1: string} $responseData + * @param array{0: string, 1: string}|array{message: string, documentation_url: string} $responseData */ public static function fromApiResponse(array $responseData): self { return new self( - documentationUrl: $responseData[1], - message: $responseData[0], + documentationUrl: $responseData[1] ?? $responseData['documentation_url'], + message: $responseData[0] ?? $responseData['message'], ); } } diff --git a/src/Module/Repository/Internal/GitHub/GitHubRepository.php b/src/Module/Repository/Internal/GitHub/GitHubRepository.php index 934c191..8b9b88f 100644 --- a/src/Module/Repository/Internal/GitHub/GitHubRepository.php +++ b/src/Module/Repository/Internal/GitHub/GitHubRepository.php @@ -7,6 +7,7 @@ use Internal\Destroy\Destroyable; use Internal\DLoad\Module\Repository\Collection\ReleasesCollection; use Internal\DLoad\Module\Repository\Internal\GitHub\Api\RepositoryApi; +use Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException; use Internal\DLoad\Module\Repository\Repository; /** @@ -73,6 +74,8 @@ public function getReleases(): ReleasesCollection // Check if there are more pages by getting next page $hasMorePages = $paginator->getNextPage() !== null; + } catch (GitHubRateLimitException $e) { + throw $e; } catch (\Throwable) { return; }