Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
cli: don't fail if rate limit is exceeded
Browse files Browse the repository at this point in the history
Don't fail if rate limit is exceeded since this is a
limitation/restriction of Github not a problem in the host.
Print a warning when the rate limit is exceeded.

For more information about Github's rate limit, see
https://developer.github.com/v3/#rate-limiting

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Nov 25, 2020
1 parent 806cc56 commit f2ff670
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cli/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package main

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -276,12 +277,17 @@ func getReleases(releaseURL string, includeAll bool) ([]semver.Version, map[stri

releasesArray := []map[string]interface{}{}

bytes, err := ioutil.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, fmt.Errorf("failed to read release details: %v", err)
} else if resp.StatusCode == http.StatusForbidden && bytes.Contains(body, []byte("limit exceeded")) {
// Do not fail if rate limit is exceeded
kataLog.WithField("url", releaseURL).
Warn("API rate limit exceeded. Try again later. Read https://docs.github.com/apps/building-github-apps/understanding-rate-limits-for-github-apps for more information")
return []semver.Version{}, map[string]releaseDetails{}, nil
}

if err := json.Unmarshal(bytes, &releasesArray); err != nil {
if err := json.Unmarshal(body, &releasesArray); err != nil {
return nil, nil, fmt.Errorf("failed to unpack release details: %v", err)
}

Expand Down

0 comments on commit f2ff670

Please sign in to comment.