aiogram/docs/dispatcher/class_based_handlers/error.md
mpa 4124770b0e refactor(handler): rename observers
Rename observers but with backward compatibility, relevant documentation
2020-05-10 03:02:31 +04:00

781 B

ErrorHandler

There is base class for error handlers.

Simple usage:

from aiogram.handlers import ErrorHandler

...

@router.errors()
class MyHandler(ErrorHandler):
    async def handle(self) -> Any:
        log.exception(
            "Cause unexpected exception %s: %s", 
            self.exception_name, 
            self.exception_message
        )

Extension

This base handler is subclass of BaseHandler with some extensions:

  • #!python3 self.exception_name is alias for #!python3 self.event.__class__.__name__
  • #!python3 self.exception_message is alias for #!python3 str(self.event)