Skip to content

Commit 598cbd2

Browse files
authored
Merge pull request #113 from utopia-php/fix/github-token-error-details
fix: include status code and response body in GitHub token error
2 parents bb42584 + 9d53fb7 commit 598cbd2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/VCS/Adapter/Git/GitHub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,10 @@ protected function generateAccessToken(string $privateKey, ?string $appId): void
636636
$this->jwtToken = $token;
637637
$response = $this->call(self::METHOD_POST, '/app/installations/' . $this->installationId . '/access_tokens', ['Authorization' => 'Bearer ' . $token]);
638638
$responseBody = $response['body'] ?? [];
639+
$statusCode = $response['headers']['status-code'] ?? 0;
639640
if (!array_key_exists('token', $responseBody)) {
640-
throw new Exception('Failed to retrieve access token from GitHub API.');
641+
$safeBody = \is_array($responseBody) ? \json_encode(\array_intersect_key($responseBody, \array_flip(['message', 'documentation_url']))) : '';
642+
throw new Exception('Failed to retrieve access token from GitHub API. Status: ' . $statusCode . '. Response: ' . $safeBody);
641643
}
642644
$this->accessToken = $responseBody['token'] ?? '';
643645
}

0 commit comments

Comments
 (0)