Merge pull request #26 from mavolin/25-retries-on-error

This commit is contained in:
diamondburned 2020-05-07 10:02:19 -07:00 committed by GitHub
commit 107c6a6563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -8,11 +8,15 @@ import (
"io"
"mime/multipart"
"github.com/pkg/errors"
"github.com/diamondburned/arikawa/utils/httputil/httpdriver"
"github.com/diamondburned/arikawa/utils/json"
"github.com/pkg/errors"
)
// StatusTooManyRequests is the HTTP status code discord sends on rate-limiting.
const StatusTooManyRequests = 429
// Retries is the default attempts to retry if the API returns an error before
// giving up. If the value is smaller than 1, then requests will retry forever.
var Retries uint = 5
@ -179,7 +183,7 @@ func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.
continue
}
if status = r.GetStatus(); status < 200 || status > 299 {
if status = r.GetStatus(); status == StatusTooManyRequests || status >= 500 {
continue
}