add response body to error if possible

This commit is contained in:
mluffman 2025-03-28 15:57:11 +00:00
parent 4ca37fbdf2
commit d4c7d7f2fc
1 changed files with 930 additions and 924 deletions

View File

@ -1056,11 +1056,17 @@ func (c *Client) fetchAccessToken(ctx context.Context, gitHubConfigURL string, c
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
return nil, &GitHubAPIError{
rErr := &GitHubAPIError{
StatusCode: resp.StatusCode,
RequestID: resp.Header.Get(HeaderGitHubRequestID),
Err: fmt.Errorf("failed to get access token for GitHub App auth: %v", resp.Status),
}
msg, err := io.ReadAll(resp.Body)
if err != nil {
return nil, rErr
}
rErr.Err = fmt.Errorf("%w: %s", rErr.Err, msg)
return nil, rErr
}
// Format: https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app