From 396ff0b7c32a21a462701c0595b978c06238faab Mon Sep 17 00:00:00 2001 From: lsiepel Date: Mon, 19 Aug 2024 08:43:48 +0200 Subject: [PATCH] [telegram] Fix log spamming when transient network issue occurs (#17116) * Fix log spam Signed-off-by: Leo Siepel Signed-off-by: Ciprian Pascu --- .../telegram/internal/TelegramHandler.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java index 5b103ef55b8..91e3935f5e7 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java @@ -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()); } }