]> git.basschouten.com Git - openhab-addons.git/commitdiff
[telegram] Fix log spamming when transient network issue occurs (#17116)
authorlsiepel <leosiepel@gmail.com>
Mon, 19 Aug 2024 06:43:48 +0000 (08:43 +0200)
committerGitHub <noreply@github.com>
Mon, 19 Aug 2024 06:43:48 +0000 (08:43 +0200)
* Fix log spam

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java

index 5b103ef55b8fc2a0376932c83d3f01cdc9d83491..91e3935f5e70c5b1c28db4a4484e0c4f886b4669 100644 (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());
         }
     }