[docs]classExceptionTypeFilter(Filter):""" Allows to match exception by type """__slots__=("exceptions",)def__init__(self,*exceptions:Type[Exception]):""" :param exceptions: Exception type(s) """ifnotexceptions:raiseValueError("At least one exception type is required")self.exceptions=exceptionsasyncdef__call__(self,obj:TelegramObject)->Union[bool,Dict[str,Any]]:returnisinstance(cast(ErrorEvent,obj).exception,self.exceptions)
[docs]classExceptionMessageFilter(Filter):""" Allow to match exception by message """__slots__=("pattern",)def__init__(self,pattern:Union[str,Pattern[str]]):""" :param pattern: Regexp pattern """ifisinstance(pattern,str):pattern=re.compile(pattern)self.pattern=patterndef__str__(self)->str:returnself._signature_to_string(pattern=self.pattern,)asyncdef__call__(self,obj:TelegramObject,)->Union[bool,Dict[str,Any]]:result=self.pattern.match(str(cast(ErrorEvent,obj).exception))ifnotresult:returnFalsereturn{"match_exception":result}