Skip to content

Commit 68af49f

Browse files
committed
Handle all exceptions in requests and add null check
1 parent 3f813f1 commit 68af49f

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

jtelegrambotapi-core/src/main/java/com/jtelegram/api/requests/framework/QueryTelegramRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public void handleResponse(Response response) throws IOException {
3434
callback.accept(gson.fromJson(result.toString(), callbackType));
3535
} catch (TelegramException ex) {
3636
handleError(ex);
37+
} catch (Exception ex) {
38+
ex.printStackTrace();
3739
}
3840
}
3941
}

jtelegrambotapi-core/src/main/java/com/jtelegram/api/requests/framework/UpdateTelegramRequest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ public void handleResponse(Response response) throws IOException {
2727

2828
if (body != null && validate(body) != null) {
2929
if (callback != null) {
30-
callback.run();
30+
try {
31+
callback.run();
32+
} catch (TelegramException ex) {
33+
handleError(ex);
34+
} catch (Exception ex) {
35+
ex.printStackTrace();
36+
}
3137
}
3238
}
3339
}

jtelegrambotapi-core/src/main/java/com/jtelegram/api/update/Update.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static abstract class TimeSensitiveUpdate extends Update {
2929
public abstract long getEventTime();
3030

3131
protected long getDateFromMessage(Message message) {
32+
if (message == null) {
33+
return -1;
34+
}
35+
3236
return message.getForwardSignature() != null ? message.getForwardDate() : message.getDate();
3337
}
3438
}

0 commit comments

Comments
 (0)