Deleted mysql support, redis password, webhook, keyboard constructors, filters, loguru.
Added support of decorators in handlers Added function to notify admins on startup
This commit is contained in:
56
handlers/errors/error_handler.py
Normal file
56
handlers/errors/error_handler.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import logging
|
||||
|
||||
from bot import dp
|
||||
|
||||
|
||||
@dp.errors_handler()
|
||||
async def errors_handler(update, exception):
|
||||
"""
|
||||
Exceptions handler. Catches all exceptions within task factory tasks.
|
||||
:param dispatcher:
|
||||
:param update:
|
||||
:param exception:
|
||||
:return: stdout logging
|
||||
"""
|
||||
from aiogram.utils.exceptions import (Unauthorized, InvalidQueryID, TelegramAPIError,
|
||||
CantDemoteChatCreator, MessageNotModified, MessageToDeleteNotFound,
|
||||
MessageTextIsEmpty, RetryAfter,
|
||||
CantParseEntities, MessageCantBeDeleted)
|
||||
|
||||
if isinstance(exception, CantDemoteChatCreator):
|
||||
logging.debug("Can't demote chat creator")
|
||||
return True
|
||||
|
||||
if isinstance(exception, MessageNotModified):
|
||||
logging.debug('Message is not modified')
|
||||
return True
|
||||
if isinstance(exception, MessageCantBeDeleted):
|
||||
logging.debug('Message cant be deleted')
|
||||
return True
|
||||
|
||||
if isinstance(exception, MessageToDeleteNotFound):
|
||||
logging.debug('Message to delete not found')
|
||||
return True
|
||||
|
||||
if isinstance(exception, MessageTextIsEmpty):
|
||||
logging.debug('MessageTextIsEmpty')
|
||||
return True
|
||||
|
||||
if isinstance(exception, Unauthorized):
|
||||
logging.info(f'Unauthorized: {exception}')
|
||||
return True
|
||||
|
||||
if isinstance(exception, InvalidQueryID):
|
||||
logging.exception(f'InvalidQueryID: {exception} \nUpdate: {update}')
|
||||
return True
|
||||
|
||||
if isinstance(exception, TelegramAPIError):
|
||||
logging.exception(f'TelegramAPIError: {exception} \nUpdate: {update}')
|
||||
return True
|
||||
if isinstance(exception, RetryAfter):
|
||||
logging.exception(f'RetryAfter: {exception} \nUpdate: {update}')
|
||||
return True
|
||||
if isinstance(exception, CantParseEntities):
|
||||
logging.exception(f'CantParseEntities: {exception} \nUpdate: {update}')
|
||||
return True
|
||||
logging.exception(f'Update: {update} \n{exception}')
|
||||
Reference in New Issue
Block a user