Skip to content

Commit

Permalink
Detect global ratelimits
Browse files Browse the repository at this point in the history
  • Loading branch information
noituri committed Sep 29, 2022
1 parent 963d0c2 commit 3856042
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
)

Expand All @@ -48,6 +49,7 @@ var (
TotalRequestsSentMutex = sync.Mutex{}
RequestsPerEndpoint = make(map[string]map[string]int)
RequestsPerEndpointMutex = sync.Mutex{}
GlobalLimitErrorCount = uint32(0)
newIdRegex, _ = regexp.Compile(`(/[a-z2-]+|/@me)+(/|)`)
keywords = []string{"applications", "audit-logs", "bans", "bot", "bulk-delete", "channels", "commands", "connections", "emojis", "gateway", "guilds", "integrations", "invites", "@me", "members", "messages", "nick", "oauth2", "permissions", "pins", "preview", "prune", "reactions", "regions", "roles", "search", "templates", "typing", "users", "voice", "webhooks", "widget", "widget.json"}
)
Expand Down Expand Up @@ -228,6 +230,9 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
rl := TooManyRequests{}
err = json.Unmarshal(response, &rl)
if err != nil {
if strings.Contains(err.Error(), `invalid character 'e'`) {
atomic.AddUint32(&GlobalLimitErrorCount, 1)
}
s.log(LogError, "rate limit unmarshal error, %s", err)
return
}
Expand Down

0 comments on commit 3856042

Please sign in to comment.