Skip to content

Commit

Permalink
add error handling for Docker Hub paid user
Browse files Browse the repository at this point in the history
  • Loading branch information
gamoutatsumi committed Jun 27, 2024
1 parent 53bfd72 commit 484ae3d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/docker/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,20 @@ func GetRateLimit() (RateLimit, error) {
return RateLimit{}, fmt.Errorf("get rate limit: %w", err)
}
defer resp.Body.Close()
limit, err := strconv.Atoi(strings.Split(resp.Header.Get("ratelimit-limit"), ";")[0])
limitHeader := resp.Header.Get("ratelimit-limit")
if limitHeader == "" {
return RateLimit{}, fmt.Errorf("not found ratelimit-limit header")
}
limit, err := strconv.Atoi(strings.Split(limitHeader, ";")[0])
if err != nil {
return RateLimit{}, fmt.Errorf("parse limit: %w", err)
}
remaining, err := strconv.Atoi(strings.Split(resp.Header.Get("ratelimit-remaining"), ";")[0])
remainingHeader := resp.Header.Get("ratelimit-remaining")
if remainingHeader == "" {
return RateLimit{}, fmt.Errorf("not found ratelimit-remaining header")

}
remaining, err := strconv.Atoi(strings.Split(remainingHeader, ";")[0])
if err != nil {
return RateLimit{}, fmt.Errorf("parse remaining: %w", err)
}
Expand Down

0 comments on commit 484ae3d

Please sign in to comment.