Skip to content

Commit d6d8171

Browse files
authored
fix: Process GitHub message with assoc content (#78)
Like `{"message":"...","documentation_ur":"..."}`
1 parent 8157820 commit d6d8171

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Module/Repository/Internal/GitHub/Api/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ private function checkForRateLimit(ResponseInterface $response): void
8686
// GitHub rate limit responses have format: ["API rate limit ...", "https://docs.github.com/..."]
8787
if (\is_array($decoded)
8888
&& \count($decoded) === 2
89-
&& \is_string($decoded[0])
90-
&& \is_string($decoded[1])
91-
&& \str_contains($decoded[0], 'API rate limit')
89+
&& \is_string(\reset($decoded))
90+
&& \is_string(\next($decoded))
91+
&& \str_contains(\reset($decoded), 'API rate limit')
9292
) {
9393
throw GitHubRateLimitException::fromApiResponse($decoded);
9494
}

src/Module/Repository/Internal/GitHub/Exception/GitHubRateLimitException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class GitHubRateLimitException extends \RuntimeException
1414
{
1515
public function __construct(
1616
public readonly string $documentationUrl,
17-
string $message = 'GitHub API rate limit exceeded',
17+
string $message = 'GitHub API rate limit exceeded. Check the GitHub Token or try again later.',
1818
?\Throwable $previous = null,
1919
) {
2020
parent::__construct($message, 0, $previous);
@@ -23,13 +23,13 @@ public function __construct(
2323
/**
2424
* Creates exception from GitHub API response body.
2525
*
26-
* @param array{0: string, 1: string} $responseData
26+
* @param array{0: string, 1: string}|array{message: string, documentation_url: string} $responseData
2727
*/
2828
public static function fromApiResponse(array $responseData): self
2929
{
3030
return new self(
31-
documentationUrl: $responseData[1],
32-
message: $responseData[0],
31+
documentationUrl: $responseData[1] ?? $responseData['documentation_url'],
32+
message: $responseData[0] ?? $responseData['message'],
3333
);
3434
}
3535
}

src/Module/Repository/Internal/GitHub/GitHubRepository.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Internal\Destroy\Destroyable;
88
use Internal\DLoad\Module\Repository\Collection\ReleasesCollection;
99
use Internal\DLoad\Module\Repository\Internal\GitHub\Api\RepositoryApi;
10+
use Internal\DLoad\Module\Repository\Internal\GitHub\Exception\GitHubRateLimitException;
1011
use Internal\DLoad\Module\Repository\Repository;
1112

1213
/**
@@ -73,6 +74,8 @@ public function getReleases(): ReleasesCollection
7374

7475
// Check if there are more pages by getting next page
7576
$hasMorePages = $paginator->getNextPage() !== null;
77+
} catch (GitHubRateLimitException $e) {
78+
throw $e;
7679
} catch (\Throwable) {
7780
return;
7881
}

0 commit comments

Comments
 (0)