Skip to content

Commit 99ada44

Browse files
Merge pull request #500 from jenkins-x/debug-github
feat: log details of failed github req/res
2 parents db7796a + 7c015da commit 99ada44

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

scm/driver/github/github.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import (
1111
"encoding/json"
1212
"errors"
1313
"fmt"
14+
"io"
1415
"net/http"
1516
"net/url"
1617
"strconv"
1718
"strings"
1819
"time"
1920

21+
"github.com/sirupsen/logrus"
22+
2023
"github.com/jenkins-x/go-scm/scm"
2124
githubql "github.com/shurcooL/githubv4"
2225
)
@@ -164,6 +167,18 @@ func (c *wrapper) doRequest(ctx context.Context, req *scm.Request, in, out inter
164167
if res.Status == 404 {
165168
return res, scm.ErrNotFound
166169
}
170+
if logrus.IsLevelEnabled(logrus.DebugLevel) && res.Body != nil {
171+
if b, err := io.ReadAll(res.Body); err == nil {
172+
logrus.WithFields(logrus.Fields{
173+
"requestMethod": req.Method,
174+
"requestPath": req.Path,
175+
"responseStatus": res.Status,
176+
"responseBody": string(b),
177+
"rate": res.Rate,
178+
"requestID": res.ID,
179+
}).Debug("GitHub responded with error")
180+
}
181+
}
167182
return res, errors.New(
168183
http.StatusText(res.Status),
169184
)

0 commit comments

Comments
 (0)