Skip to content

Commit

Permalink
better error printing on rate limit
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Jun 12, 2018
1 parent 31a394c commit ec02846
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"golang.org/x/oauth2"

Expand Down Expand Up @@ -133,6 +134,10 @@ func main() {
// Get the current user
user, _, err := client.Users.Get(ctx, "")
if err != nil {
if v, ok := err.(*github.RateLimitError); ok {
logrus.Fatalf("%s Limit: %d; Remaining: %d; Retry After: %s", v.Message, v.Rate.Limit, v.Rate.Remaining, time.Until(v.Rate.Reset.Time).String())
}

logrus.Fatal(err)
}
username := *user.Login
Expand All @@ -144,6 +149,10 @@ func main() {
perPage := 100
logrus.Debugf("Getting repositories...")
if err := getRepositories(ctx, client, page, perPage, affiliation); err != nil {
if v, ok := err.(*github.RateLimitError); ok {
logrus.Fatalf("%s Limit: %d; Remaining: %d; Retry After: %s", v.Message, v.Rate.Limit, v.Rate.Remaining, time.Until(v.Rate.Reset.Time).String())
}

logrus.Fatal(err)
}
}
Expand Down

0 comments on commit ec02846

Please sign in to comment.