Shortening error from telegram bot library

This commit is contained in:
Dita Aji Pratama 2026-09-14 13:35:51 +07:00
parent c6bae9e057
commit 680e27f9fa

View File

@ -82,8 +82,21 @@ class TelegramClient:
await self._app.shutdown()
print(f'[{_ts()}] Telegram service stopped', flush=True)
async def _error_handler(self, update, context):
from telegram.error import NetworkError
cause = context.error
if isinstance(cause, NetworkError) and "ReadError" in str(cause):
print(f'[{_ts()}] [Network Warning] Telegram ReadError occurred. Retrying...', flush=True)
else:
print(f'[{_ts()}] Exception while handling an update: {cause}', flush=True)
# Untuk error selain ReadError, tetap cetak full traceback jika perlu via logging
# atau biarkan default handler mengurusnya.
def _register_handlers(self):
from telegram.ext import MessageHandler, filters, CommandHandler
self._app.add_error_handler(self._error_handler)
self._app.add_handler(
MessageHandler(