@@ -340,9 +340,14 @@ public function getInstallationRepository(string $repositoryName): array
340340 public function getRepository (string $ owner , string $ repositoryName ): array
341341 {
342342 $ url = "/repos/ {$ owner }/ {$ repositoryName }" ;
343-
344343 $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "Bearer $ this ->accessToken " ]);
345344
345+ $ responseHeaders = $ response ['headers ' ] ?? [];
346+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
347+ if ($ responseHeadersStatusCode === 404 || $ responseHeadersStatusCode === 422 ) {
348+ throw new RepositoryNotFound ("Repository not found. " );
349+ }
350+
346351 return $ response ['body ' ] ?? [];
347352 }
348353
@@ -765,6 +770,15 @@ public function getCommit(string $owner, string $repositoryName, string $commitH
765770
766771 $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "Bearer $ this ->accessToken " ]);
767772
773+ $ responseHeaders = $ response ['headers ' ] ?? [];
774+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
775+ if ($ responseHeadersStatusCode === 404 ) {
776+ throw new RepositoryNotFound ("Commit not found. " );
777+ }
778+ if ($ responseHeadersStatusCode === 422 ) {
779+ throw new Exception ("Commit not found or inaccessible. " );
780+ }
781+
768782 $ responseBody = $ response ['body ' ] ?? [];
769783 $ responseBodyAuthor = $ responseBody ['author ' ] ?? [];
770784 $ responseBodyCommit = $ responseBody ['commit ' ] ?? [];
@@ -794,6 +808,12 @@ public function getLatestCommit(string $owner, string $repositoryName, string $b
794808
795809 $ response = $ this ->call (self ::METHOD_GET , $ url , ['Authorization ' => "Bearer $ this ->accessToken " ]);
796810
811+ $ responseHeaders = $ response ['headers ' ] ?? [];
812+ $ responseHeadersStatusCode = $ responseHeaders ['status-code ' ] ?? 0 ;
813+ if ($ responseHeadersStatusCode === 404 ) {
814+ throw new RepositoryNotFound ("Branch not found: {$ branch }" );
815+ }
816+
797817 $ responseBody = $ response ['body ' ] ?? [];
798818 $ responseBodyCommit = $ responseBody ['commit ' ] ?? [];
799819 $ responseBodyCommitAuthor = $ responseBodyCommit ['author ' ] ?? [];
0 commit comments