[docs]classExceptionTypeFilter(Filter):""" Allows to match exception by type """__slots__=("exceptions",)def__init__(self,*exceptions:type[Exception]):""" :param exceptions: Exception type(s) """ifnotexceptions:msg="At least one exception type is required"raiseValueError(msg)self.exceptions=exceptionsasyncdef__call__(self,obj:TelegramObject)->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: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,)->bool|dict[str,Any]:result=self.pattern.match(str(cast(ErrorEvent,obj).exception))ifnotresult:returnFalsereturn{"match_exception":result}