Skip to content

Commit

Permalink
restapi: retry on 500s as well as 502s
Browse files Browse the repository at this point in the history
This is a sequel to issue #227.

I run a matterbridge bridge and I'm getting 500s from the Discord API
from time to time. We should treat them the same as a 503, instead of
just immediately giving up.

Since we're adding entries to the switch statement, also clean up the
naked 429 to be consistent.
  • Loading branch information
patrickxia committed Nov 23, 2024
1 parent 247b6f7 commit 6520f27
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
case http.StatusOK:
case http.StatusCreated:
case http.StatusNoContent:
case http.StatusInternalServerError:
fallthrough
case http.StatusBadGateway:
// Retry sending request if possible
if sequence < cfg.MaxRestRetries {
Expand All @@ -275,7 +277,7 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
} else {
err = fmt.Errorf("Exceeded Max retries HTTP %s, %s", resp.Status, response)
}
case 429: // TOO MANY REQUESTS - Rate limiting
case http.StatusTooManyRequests:
rl := TooManyRequests{}
err = Unmarshal(response, &rl)
if err != nil {
Expand Down

0 comments on commit 6520f27

Please sign in to comment.