forked from pothtonswer/discordmuffin
Initial, very basic, support for dealing with rate limits
This commit is contained in:
parent
70d420f16b
commit
4bdb631758
1 changed files with 14 additions and 2 deletions
14
restapi.go
14
restapi.go
|
@ -88,7 +88,19 @@ func (s *Session) Request(method, urlStr string, data interface{}) (response []b
|
|||
case 204: // No Content
|
||||
|
||||
// TODO check for 401 response, invalidate token if we get one.
|
||||
// TODO check for 429 response, rate-limit when we get one.
|
||||
|
||||
case 429: // TOO MANY REQUESTS - Rate limiting
|
||||
// This will be changed to a more robust method later.
|
||||
// which may be hugely different as this method could cause
|
||||
// unending recursion
|
||||
rl := RateLimit{}
|
||||
err = json.Unmarshal(response, &rl)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Request unmarshal rate limit error : ", err)
|
||||
return
|
||||
}
|
||||
time.Sleep(rl.RetryAfter)
|
||||
response, err = s.Request(method, urlStr, data)
|
||||
|
||||
default: // Error condition
|
||||
err = fmt.Errorf("HTTP %s, %s", resp.Status, response)
|
||||
|
|
Loading…
Reference in a new issue