rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.79k stars 1.23k forks source link

Error received from Telegram GetUpdates Request: null: Telegram API error details being masked by bad exception handling #1452

Open twaslowski opened 2 weeks ago

twaslowski commented 2 weeks ago

Describe the bug

I'm currently getting the following stacktrace:

2024-11-04 07:27:28,201 ERROR [pool-4-thread-1] o.t.t.l.BotSession - [] Error received from Telegram GetUpdates Request, retrying in 269 millis...
org.telegram.telegrambots.longpolling.exceptions.TelegramApiErrorResponseException: null
    at org.telegram.telegrambots.longpolling.BotSession.getUpdatesFromTelegram(BotSession.java:156)
    at org.telegram.telegrambots.longpolling.BotSession.lambda$createPollerTask$1(BotSession.java:103)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
    at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: org.telegram.telegrambots.longpolling.exceptions.TelegramApiErrorResponseException:
    at org.telegram.telegrambots.longpolling.BotSession.getUpdatesFromTelegram(BotSession.java:152)
    ... 7 common frames omitted

Expected behavior

If the Telegram API responds with a non-2xx status code, I should be able to see error details. When the API response is unsuccessful, a TelegramApiErrorResponseException containing the status code and message is thrown. However, this exception is immediately caught and wrapped in an instance of itself, with the code simply being overwritten/nulled, as can be seen here.

Additional context

Something like this shows up in #1401 as well, it seems.

I'll do some experiments with a fork of this project to see if I can make some progress on this myself. I just wanted to have this issue tracked in case other people run into it as well.

twaslowski commented 2 weeks ago

Addressed by #1453.