Skip to content

Commit 3eacbeb

Browse files
committed
handle watch send msg perms revoked
1 parent bd34c6c commit 3eacbeb

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

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

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,20 @@ private <T extends UserWatch> void sendUserWatchNotification(
325325
"Retries exhausted sending " + targetName + " notification to user: " + userWatch.ownerUserName() + ", channelId: " + channel.getId().asString(),
326326
signal.failure())))
327327
.onErrorResume(error -> {
328-
if (Exceptions.isRetryExhausted(error)) {
329-
if (error instanceof ClientException e) {
330-
int code = e.getStatus().code();
331-
if (code == 429) {
332-
LOGGER.error("Rate limited while sending {} notification to user: {}", targetName, userWatch.ownerUserName());
333-
} else if (code == 403 || code == 404) {
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-
}
328+
if (error instanceof ClientException e) {
329+
int code = e.getStatus().code();
330+
if (code == 429) {
331+
LOGGER.error("Rate limited while sending {} notification to user: {}", targetName, userWatch.ownerUserName());
332+
} else if (code == 403 || code == 404) {
333+
var cloudflareError = e.getErrorResponse()
334+
.map(r -> r.getFields().get("body"))
335+
.filter(body -> body instanceof String)
336+
.map(body -> (String) body)
337+
.map(body -> body.contains("cloudflare"))
338+
.orElse(false);
339+
if (!cloudflareError) {
340+
LOGGER.error("Missing permissions while sending {} notification to user: {}. Removing watch.", targetName, userWatch.ownerUserName());
341+
removeWatchConsumer.accept(userWatch);
344342
}
345343
}
346344
}
@@ -397,22 +395,20 @@ private <T extends GuildWatch> void sendGuildNotification(
397395
"Retries exhausted sending " + targetName + " notification to guild: " + guildWatch.guildId() + ", channelId: " + channel.getId().asString(),
398396
signal.failure())))
399397
.onErrorResume(error -> {
400-
if (Exceptions.isRetryExhausted(error)) {
401-
if (error instanceof ClientException e) {
402-
int code = e.getStatus().code();
403-
if (code == 429) {
404-
LOGGER.error("Rate limited while sending {} notification to guild: {}, channelId: {}.", targetName, guildWatch.guildId(), channel.getId());
405-
} else if (code == 403 || code == 404) {
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-
}
398+
if (error instanceof ClientException e) {
399+
int code = e.getStatus().code();
400+
if (code == 429) {
401+
LOGGER.error("Rate limited while sending {} notification to guild: {}, channelId: {}.", targetName, guildWatch.guildId(), channel.getId());
402+
} else if (code == 403 || code == 404) {
403+
var cloudflareError = e.getErrorResponse()
404+
.map(r -> r.getFields().get("body"))
405+
.filter(body -> body instanceof String)
406+
.map(body -> (String) body)
407+
.map(body -> body.contains("cloudflare"))
408+
.orElse(false);
409+
if (!cloudflareError) {
410+
LOGGER.error("Missing permissions while sending {} notification to guild: {}, channelId: {}. Removing watch.", targetName, guildWatch.guildId(), channel.getId());
411+
removeGuildWatchFunction.accept(guildWatch);
416412
}
417413
}
418414
}

0 commit comments

Comments
 (0)