@@ -224,23 +224,32 @@ private void handleExceptions(@Nullable TelegramException exception) {
224
224
if (exception != null ) {
225
225
if (exception .response () != null ) {
226
226
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 ;
235
245
}
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
238
247
cancelThingOnlineStatusJob ();
239
248
updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .COMMUNICATION_ERROR , exception .getMessage ());
240
249
delayThingOnlineStatus ();
241
- return ;
250
+ } else {
251
+ logger .warn ("Telegram exception: {}" , exception .getMessage ());
242
252
}
243
- logger .warn ("Telegram exception: {}" , exception .getMessage ());
244
253
}
245
254
}
246
255
0 commit comments