File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
src/Module/Repository/Internal/GitHub Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 77use Internal \Destroy \Destroyable ;
88use Internal \DLoad \Module \Repository \Collection \ReleasesCollection ;
99use Internal \DLoad \Module \Repository \Internal \GitHub \Api \RepositoryApi ;
10+ use Internal \DLoad \Module \Repository \Internal \GitHub \Exception \GitHubRateLimitException ;
1011use 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 }
You can’t perform that action at this time.
0 commit comments