Shortening error from telegram bot library
This commit is contained in:
parent
c6bae9e057
commit
680e27f9fa
@ -82,9 +82,22 @@ 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(
|
||||
filters.TEXT & ~filters.COMMAND & filters.ChatType.PRIVATE,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user