Add response body to error when fetching access token (#4005)

Co-authored-by: mluffman <mluffman@thoughtmachine.net>
Co-authored-by: Nikola Jokic <jokicnikola07@gmail.com>
This commit is contained in:
Nash Luffman 2025-06-11 14:52:38 +01:00 committed by GitHub
parent c359d14e69
commit e335f53037
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -1060,10 +1060,15 @@ func (c *Client) fetchAccessToken(ctx context.Context, gitHubConfigURL string, c
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated { if resp.StatusCode != http.StatusCreated {
errMsg := fmt.Sprintf("failed to get access token for GitHub App auth (%v)", resp.Status)
if body, err := io.ReadAll(resp.Body); err == nil {
errMsg = fmt.Sprintf("%s: %s", errMsg, string(body))
}
return nil, &GitHubAPIError{ return nil, &GitHubAPIError{
StatusCode: resp.StatusCode, StatusCode: resp.StatusCode,
RequestID: resp.Header.Get(HeaderGitHubRequestID), RequestID: resp.Header.Get(HeaderGitHubRequestID),
Err: fmt.Errorf("failed to get access token for GitHub App auth: %v", resp.Status), Err: errors.New(errMsg),
} }
} }