Skip to content

Commit

Permalink
Expand list of retried http error codes (#2710)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Aug 2, 2024
1 parent fb1a339 commit 3b15a55
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/net/dv8tion/jda/internal/requests/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@

public class Requester
{
private static final int[] RETRY_ERROR_CODES = {
502, // bad gateway
503, // service temporarily unavailable
504, // gateway timeout
520, // web server returns an unknown error
521, // web server is down
522, // connection timed out
523, // origin is unreachable
524, // a timeout occurred
529, // The service is overloaded
};

public static final Logger LOG = JDALogger.getLog(Requester.class);
@SuppressWarnings("deprecation")
public static final RequestBody EMPTY_BODY = RequestBody.create(null, new byte[0]);
Expand Down Expand Up @@ -341,7 +353,14 @@ public void stop(boolean shutdown, Runnable callback)

private static boolean shouldRetry(int code)
{
return code == 502 || code == 504 || code == 529;
if (code < RETRY_ERROR_CODES[0] || code > RETRY_ERROR_CODES[RETRY_ERROR_CODES.length - 1])
return false;
for (int retryCode : RETRY_ERROR_CODES)
{
if (retryCode == code)
return true;
}
return false;
}

private long parseRetry(okhttp3.Response response)
Expand Down

0 comments on commit 3b15a55

Please sign in to comment.