Skip to content

Commit 62cd6e6

Browse files
committed
catch cloudflare 403 errors
1 parent 53f8e29 commit 62cd6e6

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/main/java/vc/live/LiveFeed.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,21 @@ private void handleBroadcastError(final Throwable error, final String guildId, f
250250
LOGGER.error("Rate limited while broadcasting message to channel: {}", channel.getId().asString());
251251
return;
252252
} else if (code == 403 || code == 404) {
253-
// missing permissions or channel deleted, disable immediately
254-
LOGGER.error("Missing permissions while broadcasting message to channel: {}", channel.getId().asString());
255-
disableFeed(guildId);
256-
return;
253+
var cloudflareError = e.getErrorResponse()
254+
.map(r -> r.getFields().get("body"))
255+
.filter(body -> body instanceof String)
256+
.map(body -> (String) body)
257+
.map(body -> body.contains("cloudflare"))
258+
.orElse(false);
259+
if (cloudflareError) {
260+
LOGGER.error("Cloudflare error while broadcasting message to channel: {}", channel.getId().asString(), error);
261+
return;
262+
} else {
263+
// missing permissions or channel deleted, disable immediately
264+
LOGGER.error("Missing permissions while broadcasting message to channel: {}", channel.getId().asString());
265+
disableFeed(guildId);
266+
return;
267+
}
257268
}
258269
}
259270
// for any unknown error, count it and disable if we get too many

src/main/java/vc/live/watch/WatchManager.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,16 @@ private <T extends UserWatch> void sendUserWatchNotification(
331331
if (code == 429) {
332332
LOGGER.error("Rate limited while sending {} notification to user: {}", targetName, userWatch.ownerUserName());
333333
} else if (code == 403 || code == 404) {
334-
LOGGER.error("Missing permissions while sending {} notification to user: {}. Removing watch.", targetName, userWatch.ownerUserName());
335-
removeWatchConsumer.accept(userWatch);
334+
var cloudflareError = e.getErrorResponse()
335+
.map(r -> r.getFields().get("body"))
336+
.filter(body -> body instanceof String)
337+
.map(body -> (String) body)
338+
.map(body -> body.contains("cloudflare"))
339+
.orElse(false);
340+
if (!cloudflareError) {
341+
LOGGER.error("Missing permissions while sending {} notification to user: {}. Removing watch.", targetName, userWatch.ownerUserName());
342+
removeWatchConsumer.accept(userWatch);
343+
}
336344
}
337345
}
338346
}
@@ -395,8 +403,16 @@ private <T extends GuildWatch> void sendGuildNotification(
395403
if (code == 429) {
396404
LOGGER.error("Rate limited while sending {} notification to guild: {}, channelId: {}.", targetName, guildWatch.guildId(), channel.getId());
397405
} else if (code == 403 || code == 404) {
398-
LOGGER.error("Missing permissions while sending {} notification to guild: {}, channelId: {}. Removing watch.", targetName, guildWatch.guildId(), channel.getId());
399-
removeGuildWatchFunction.accept(guildWatch);
406+
var cloudflareError = e.getErrorResponse()
407+
.map(r -> r.getFields().get("body"))
408+
.filter(body -> body instanceof String)
409+
.map(body -> (String) body)
410+
.map(body -> body.contains("cloudflare"))
411+
.orElse(false);
412+
if (!cloudflareError) {
413+
LOGGER.error("Missing permissions while sending {} notification to guild: {}, channelId: {}. Removing watch.", targetName, guildWatch.guildId(), channel.getId());
414+
removeGuildWatchFunction.accept(guildWatch);
415+
}
400416
}
401417
}
402418
}

0 commit comments

Comments
 (0)