[telegram] Fix log spamming when transient network issue occurs (#17116)

* Fix log spam

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
lsiepel 2024-08-19 08:43:48 +02:00 committed by Ciprian Pascu
parent 6a3d77918e
commit 396ff0b7c3

View File

@ -224,23 +224,32 @@ public class TelegramHandler extends BaseThingHandler {
if (exception != null) {
if (exception.response() != null) {
BaseResponse localResponse = exception.response();
if (localResponse.errorCode() == 401) { // unauthorized
cancelThingOnlineStatusJob();
if (localBot != null) {
localBot.removeGetUpdatesListener();
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Unauthorized attempt to connect to the Telegram server, please check if the bot token is valid");
return;
switch (localResponse.errorCode()) {
case 401: // unauthorized
cancelThingOnlineStatusJob();
if (localBot != null) {
localBot.removeGetUpdatesListener();
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Unauthorized attempt to connect to the Telegram server, please check if the bot token is valid");
return;
case 502:
cancelThingOnlineStatusJob();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unable to communicate to Telegram servers, check your connection");
delayThingOnlineStatus();
return;
default:
logger.warn("Telegram exception: {}", exception.getMessage());
return;
}
}
if (exception.getCause() != null) { // cause is only non-null in case of an IOException
} else if (exception.getCause() != null) { // cause is only non-null in case of an IOException
cancelThingOnlineStatusJob();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, exception.getMessage());
delayThingOnlineStatus();
return;
} else {
logger.warn("Telegram exception: {}", exception.getMessage());
}
logger.warn("Telegram exception: {}", exception.getMessage());
}
}