Skip to content

Commit

Permalink
Fix error when resetAfter header is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
germanoeich committed Sep 29, 2021
1 parent 28b6a60 commit be11a9e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,18 @@ func parseHeaders(headers *http.Header) (int64, int64, time.Duration, bool, erro
}
isGlobal := headers.Get("x-ratelimit-global") == "true"

resetParsed, err := strconv.ParseFloat(resetAfter, 64)
if err != nil {
return 0, 0, 0, false, err
}
var resetParsed float64
var reset time.Duration
var err error
if resetAfter != "" {
resetParsed, err = strconv.ParseFloat(resetAfter, 64)
if err != nil {
return 0, 0, 0, false, err
}

// Convert to MS instead of seconds to preserve decimal precision
reset := time.Duration(int(resetParsed * 1000)) * time.Millisecond
// Convert to MS instead of seconds to preserve decimal precision
reset = time.Duration(int(resetParsed * 1000)) * time.Millisecond
}

if isGlobal {
return 0, 0, reset, isGlobal, nil
Expand Down

0 comments on commit be11a9e

Please sign in to comment.