Skip to content

Commit d33b2ff

Browse files
authored
[telegram] Fix log spamming when transient network issue occurs (openhab#17116)
* Fix log spam Signed-off-by: Leo Siepel <[email protected]>
1 parent 31cca5e commit d33b2ff

File tree

1 file changed

+21
-12
lines changed
  • bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal

1 file changed

+21
-12
lines changed

bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,32 @@ private void handleExceptions(@Nullable TelegramException exception) {
224224
if (exception != null) {
225225
if (exception.response() != null) {
226226
BaseResponse localResponse = exception.response();
227-
if (localResponse.errorCode() == 401) { // unauthorized
228-
cancelThingOnlineStatusJob();
229-
if (localBot != null) {
230-
localBot.removeGetUpdatesListener();
231-
}
232-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
233-
"Unauthorized attempt to connect to the Telegram server, please check if the bot token is valid");
234-
return;
227+
switch (localResponse.errorCode()) {
228+
case 401: // unauthorized
229+
cancelThingOnlineStatusJob();
230+
if (localBot != null) {
231+
localBot.removeGetUpdatesListener();
232+
}
233+
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
234+
"Unauthorized attempt to connect to the Telegram server, please check if the bot token is valid");
235+
return;
236+
case 502:
237+
cancelThingOnlineStatusJob();
238+
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
239+
"Unable to communicate to Telegram servers, check your connection");
240+
delayThingOnlineStatus();
241+
return;
242+
default:
243+
logger.warn("Telegram exception: {}", exception.getMessage());
244+
return;
235245
}
236-
}
237-
if (exception.getCause() != null) { // cause is only non-null in case of an IOException
246+
} else if (exception.getCause() != null) { // cause is only non-null in case of an IOException
238247
cancelThingOnlineStatusJob();
239248
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, exception.getMessage());
240249
delayThingOnlineStatus();
241-
return;
250+
} else {
251+
logger.warn("Telegram exception: {}", exception.getMessage());
242252
}
243-
logger.warn("Telegram exception: {}", exception.getMessage());
244253
}
245254
}
246255

0 commit comments

Comments
 (0)