mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-04 18:47:50 +01:00
Add better global/cloudflare ratelimit error
This commit is contained in:
parent
824a392414
commit
181f8035b4
@ -19,11 +19,13 @@
|
||||
package com.discordsrv.common.core.logging.impl;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.helper.Timeout;
|
||||
import com.discordsrv.common.logging.LogAppender;
|
||||
import com.discordsrv.common.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
@ -31,6 +33,7 @@ public class DependencyLoggingHandler implements LogAppender {
|
||||
|
||||
private static final Map<String, List<String>> BLACKLISTED_MESSAGES = new HashMap<>();
|
||||
private static final Map<String, String> LOGGER_MAPPINGS = new HashMap<>();
|
||||
private static final Timeout RATELIMIT_TIMEOUT = new Timeout(Duration.ofSeconds(20));
|
||||
|
||||
static {
|
||||
// Class names here will get relocated, which is fine
|
||||
@ -93,6 +96,23 @@ public class DependencyLoggingHandler implements LogAppender {
|
||||
}
|
||||
}
|
||||
|
||||
if (name.equals("JDA") && message != null &&
|
||||
(message.startsWith("Encountered global rate limit!")
|
||||
|| message.startsWith("Encountered cloudflare rate limit!"))) {
|
||||
if (!RATELIMIT_TIMEOUT.checkAndUpdate()) {
|
||||
discordSRV.logger().warning(message);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean usingProxy = discordSRV.connectionConfig().httpProxy.enabled;
|
||||
discordSRV.logger().warning("+------------------------------------------>");
|
||||
discordSRV.logger().warning("| " + message);
|
||||
discordSRV.logger().warning("| This means the " + (usingProxy ? "proxy" : "server") + "'s ip is sending too many requests to Discord");
|
||||
discordSRV.logger().warning("| The ip is being temporarily restricted from making requests to Discord");
|
||||
discordSRV.logger().warning("+------------------------------------------>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.equals("JDA") && message != null
|
||||
&& message.contains("Got an unexpected error. Please redirect the following message to the devs:")
|
||||
&& throwable instanceof RejectedExecutionException
|
||||
|
Loading…
Reference in New Issue
Block a user