Skip to content

Commit 749bc5d

Browse files
committed
Attempt to log the message from the response for a failed API request to GitHub
1 parent e94bcab commit 749bc5d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,15 @@ func main() {
257257
return true, nil
258258
}
259259

260-
// Token not authorized for org
261-
if resp.StatusCode == http.StatusForbidden {
262-
errResp := GitHubError{}
260+
errResp := GitHubError{}
261+
if resp.StatusCode >= 400 && resp.StatusCode < 500 {
263262
if err = unmarshalResp(resp, &errResp); err != nil {
264263
return false, err
265264
}
265+
}
266+
267+
// Token not authorized for org
268+
if resp.StatusCode == http.StatusForbidden {
266269
if match, err := regexp.MatchString("SAML enforcement", errResp.Message); err != nil {
267270
return false, fmt.Errorf("matching 403 response: %v", err)
268271
} else if match {
@@ -298,7 +301,7 @@ func main() {
298301

299302
for _, status := range retryableStatuses {
300303
if resp.StatusCode == status {
301-
logger.Trace("retrying failed API request", "method", requestMethod, "url", requestUrl, "status", resp.StatusCode)
304+
logger.Trace("retrying failed API request", "method", requestMethod, "url", requestUrl, "status", resp.StatusCode, "message", errResp.Message)
302305
return true, nil
303306
}
304307
}

0 commit comments

Comments
 (0)