@@ -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