aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-07 17:33:16 +0300
committerGravatar Vitaly Takmazov2018-04-07 17:33:16 +0300
commit53586f7dc92c47bf45e33c2cd086a32a8da1a250 (patch)
tree5504a9f4419e57796862fb3a9d92dfa7400e4899
parent520271c29ef92bb16f540ced38b71e5b406f8af9 (diff)
server: handle telegram webhook exceptions
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java36
1 files changed, 25 insertions, 11 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
index b0803265..e1bdad1f 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -104,7 +104,7 @@ public class TelegramBotManager implements NotificationListener {
}
}
- public void processUpdate(String data) throws Exception {
+ public void processUpdate(String data) {
Update update = BotUtils.parseUpdate(data);
Message message = update.message();
if (update.message() == null) {
@@ -139,8 +139,12 @@ public class TelegramBotManager implements NotificationListener {
GetFile request = new GetFile(fileId);
GetFileResponse response = bot.execute(request);
logger.info("got file {}", response.file());
- URL fileURL = new URL(bot.getFullFilePath(response.file()));
- attachment = HttpUtils.downloadImage(fileURL, tmpDir);
+ try {
+ URL fileURL = new URL(bot.getFullFilePath(response.file()));
+ attachment = HttpUtils.downloadImage(fileURL, tmpDir);
+ } catch (Exception e) {
+ logger.warn("attachment exception", e);
+ }
logger.info("received {}", attachment);
}
}
@@ -185,10 +189,15 @@ public class TelegramBotManager implements NotificationListener {
int rid = Integer.valueOf(uriComponents.getFragment());
prefix = String.format("#%d/%d ", mid, rid);
}
- CommandResult result = commandsManager.processCommand(user_from, prefix + text, attachment);
- String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
- : "Unknown error or unsupported command";
- telegramNotify(message.from().id().longValue(), messageTxt, StringUtils.EMPTY);
+ CommandResult result = null;
+ try {
+ result = commandsManager.processCommand(user_from, prefix + text, attachment);
+ String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
+ : "Unknown error or unsupported command";
+ telegramNotify(message.from().id().longValue(), messageTxt, StringUtils.EMPTY);
+ } catch (Exception e) {
+ logger.warn("telegram exception", e);
+ }
} else {
logger.warn("invalid path: {}", path);
}
@@ -204,10 +213,15 @@ public class TelegramBotManager implements NotificationListener {
"Can not reply to this message", replyMessage.messageId(), StringUtils.EMPTY);
}
} else {
- CommandResult result = commandsManager.processCommand(user_from, text, attachment);
- String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
- : "Unknown error or unsupported command";
- telegramNotify(message.from().id().longValue(), messageTxt, StringUtils.EMPTY);
+ CommandResult result = null;
+ try {
+ result = commandsManager.processCommand(user_from, text, attachment);
+ String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
+ : "Unknown error or unsupported command";
+ telegramNotify(message.from().id().longValue(), messageTxt, StringUtils.EMPTY);
+ } catch (Exception e) {
+ logger.warn("telegram reply exception", e);
+ }
}
}
}