1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-04-11 23:54:30 +00:00

Utils: Fixed bug where retries aren't applied options again, causing rate limits

This commit is contained in:
diamondburned (Forefront) 2020-05-05 15:32:28 -07:00
parent 3536ae4cb6
commit 0c24ac627b

View file

@ -151,20 +151,30 @@ func (c *Client) RequestJSON(to interface{}, method, url string, opts ...Request
} }
func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.Response, error) { func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.Response, error) {
req, err := c.Client.NewRequest(c.context, method, url) var err error
if err != nil {
return nil, RequestError{err}
}
if err := c.applyOptions(req, opts); err != nil {
return nil, errors.Wrap(err, "Failed to apply options")
}
var r httpdriver.Response var r httpdriver.Response
var status int var status int
for i := uint(0); c.Retries < 1 || i < c.Retries; i++ { for i := uint(0); c.Retries < 1 || i < c.Retries; i++ {
r, err = c.Client.Do(req) q, err := c.Client.NewRequest(c.context, method, url)
if err != nil {
return nil, RequestError{err}
}
if err := c.applyOptions(q, opts); err != nil {
return nil, errors.Wrap(err, "Failed to apply options")
}
r, err = c.Client.Do(q)
// Call OnResponse() even if the request failed.
for _, fn := range c.OnResponse {
if err := fn(q, r); err != nil {
return nil, err
}
}
if err != nil { if err != nil {
continue continue
} }
@ -176,13 +186,6 @@ func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.
break break
} }
// Call OnResponse() even if the request failed.
for _, fn := range c.OnResponse {
if err := fn(req, r); err != nil {
return nil, err
}
}
// If all retries failed: // If all retries failed:
if err != nil { if err != nil {
return nil, RequestError{err} return nil, RequestError{err}