rubenlagus / TelegramBots

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

Display server error also, during exception #169

Closed ceefour closed 7 years ago

ceefour commented 7 years ago

When exception occurs during LongPolling and cannot get updates, exception is shown however the reason for the error is not shown (e.g. long polling is conflict by other long polling process).

rubenlagus commented 7 years ago

Are you registering a handler in the BotLogger? In my console I get this when having that problem:

Nov 27, 2016 5:23:22 PM org.telegram.telegrambots.logging.BotLogger severe
SEVERE: BOTSESSION
org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error getting updates: [409] Conflict: terminated by other long poll or webhook
    at org.telegram.telegrambots.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:96)
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:177)
ceefour commented 7 years ago

I am not aware of BotLogger. I am just using Logback which is configured by Spring Boot.

I suggest just configuring Java logging should be sufficient to get detailed error, without configuring a special BotLogger.

On Sun, Nov 27, 2016, 23:25 Ruben Bermudez notifications@github.com wrote:

Are you registering a handler in the BotLogger? In my console I get this when having that problem:

Nov 27, 2016 5:23:22 PM org.telegram.telegrambots.logging.BotLogger severe SEVERE: BOTSESSION org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error getting updates: [409] Conflict: terminated by other long poll or webhook at org.telegram.telegrambots.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:96) at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:177)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rubenlagus/TelegramBots/issues/169#issuecomment-263131360, or mute the thread https://github.com/notifications/unsubscribe-auth/AABeO690jYnAwg0rOKctS1igUQob3noQks5rCa7igaJpZM4K9LM7 .

rubenlagus commented 7 years ago

BotLogger is just using java.util.logging, I'm not sure what is Logback doing, but BotLogger will just log everything to the default java.util.logging. You can add whatever handler you like to JUL loggers and as long as you make it before initialisation of the first Bot, you should get the correct output there.

I can't add support for every logging library around there, so I added it only for the default one.

ceefour commented 7 years ago

@rubenlagus It seems the problem is not logging but the error stacktrace. The required information is not put in the Exception's "toString" :

2016-11-28 10:20:37.982 ERROR 12368 --- [legram Executor] Telegram Bots Api                        : BOTSESSION

org.crayonpedia.yoopa.bot.YoopaBotException: Cannot process chat message: @lpdpbot logo
    at org.crayonpedia.yoopa.bot.ContentfulHandlerImpl.onUpdateReceived(ContentfulHandlerImpl.java:100) ~[classes/:na]
    at org.crayonpedia.yoopa.bot.ContentfulHandlerImpl$$FastClassBySpringCGLIB$$cb9fcc84.invoke(<generated>) ~[na:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.crayonpedia.yoopa.bot.ContentfulHandlerImpl$$EnhancerBySpringCGLIB$$c6e6af7c.onUpdateReceived(<generated>) ~[na:na]
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:241) ~[telegrambots-2.4.4.jar:na]
Caused by: org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error sending message
    at org.telegram.telegrambots.api.methods.send.SendMessage.deserializeResponse(SendMessage.java:163) ~[telegrambots-meta-2.4.4.jar:na]
    at org.telegram.telegrambots.api.methods.send.SendMessage.deserializeResponse(SendMessage.java:23) ~[telegrambots-meta-2.4.4.jar:na]
    at org.telegram.telegrambots.bots.DefaultAbsSender.sendApiMethod(DefaultAbsSender.java:678) ~[telegrambots-2.4.4.jar:na]
    at org.telegram.telegrambots.bots.AbsSender.sendMessage(AbsSender.java:66) ~[telegrambots-meta-2.4.4.jar:na]
    at org.crayonpedia.yoopa.bot.ContentfulHandlerImpl.onUpdateReceived(ContentfulHandlerImpl.java:88) ~[classes/:na]
    ... 11 common frames omitted

I believe there's something else beyond just "Error sending message", but it's not visible in the stack trace.

rubenlagus commented 7 years ago

If there is any kind of api answer to the error and/or error_code, it is added to the toString method:

https://github.com/rubenlagus/TelegramBots/blob/master/telegrambots-meta/src/main/java/org/telegram/telegrambots/exceptions/TelegramApiRequestException.java#L87