From cbbae051be7f91423091a56d13bf201d86a8564a Mon Sep 17 00:00:00 2001 From: bivashy Date: Mon, 15 Jul 2024 16:56:04 +0500 Subject: [PATCH] Ignore ApiMessagesDenySendException in VK link --- .../auth/vk/command/VKCommandRegistry.java | 2 ++ .../command/exception/VKExceptionHandler.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 core/src/main/java/me/mastercapexd/auth/vk/command/exception/VKExceptionHandler.java diff --git a/core/src/main/java/me/mastercapexd/auth/vk/command/VKCommandRegistry.java b/core/src/main/java/me/mastercapexd/auth/vk/command/VKCommandRegistry.java index 8e4bdcc6..845f3eba 100644 --- a/core/src/main/java/me/mastercapexd/auth/vk/command/VKCommandRegistry.java +++ b/core/src/main/java/me/mastercapexd/auth/vk/command/VKCommandRegistry.java @@ -12,6 +12,7 @@ import me.mastercapexd.auth.messenger.commands.MessengerCommandRegistry; import me.mastercapexd.auth.shared.commands.MessengerLinkCommandTemplate; import me.mastercapexd.auth.shared.commands.VKLinkCommand; +import me.mastercapexd.auth.vk.command.exception.VKExceptionHandler; import revxrsal.commands.CommandHandler; public class VKCommandRegistry extends MessengerCommandRegistry { @@ -21,6 +22,7 @@ public class VKCommandRegistry extends MessengerCommandRegistry { public VKCommandRegistry() { super(COMMAND_HANDLER, VKLinkType.getInstance()); COMMAND_HANDLER.registerContextResolver(LinkCommandActorWrapper.class, context -> new VKCommandActorWrapper(context.actor())); + COMMAND_HANDLER.setExceptionHandler(new VKExceptionHandler(VKLinkType.getInstance())); registerCommands(); try { diff --git a/core/src/main/java/me/mastercapexd/auth/vk/command/exception/VKExceptionHandler.java b/core/src/main/java/me/mastercapexd/auth/vk/command/exception/VKExceptionHandler.java new file mode 100644 index 00000000..e3202220 --- /dev/null +++ b/core/src/main/java/me/mastercapexd/auth/vk/command/exception/VKExceptionHandler.java @@ -0,0 +1,21 @@ +package me.mastercapexd.auth.vk.command.exception; + +import com.bivashy.auth.api.link.LinkType; +import com.vk.api.sdk.exceptions.ApiMessagesDenySendException; +import me.mastercapexd.auth.messenger.commands.exception.MessengerExceptionHandler; +import revxrsal.commands.command.CommandActor; + +public class VKExceptionHandler extends MessengerExceptionHandler { + + public VKExceptionHandler(LinkType linkType) { + super(linkType); + } + + @Override + public void onUnhandledException(CommandActor actor, Throwable throwable) { + if (throwable instanceof ApiMessagesDenySendException) + return; + super.onUnhandledException(actor, throwable); + } + +}