mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Check error handler callback args to prevent cycled exceptions
This commit is contained in:
parent
61e0f3601d
commit
fb9fb68130
1 changed files with 8 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import itertools
|
|||
import logging
|
||||
import time
|
||||
import typing
|
||||
from inspect import signature
|
||||
|
||||
from .filters import Command, ContentTypeFilter, ExceptionsFilter, FiltersFactory, FuncFilter, HashTag, Regexp, \
|
||||
RegexpCommandsFilter, StateFilter, Text
|
||||
|
|
@ -812,6 +813,12 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
|
|||
:param exception: you can make handler for specific errors type
|
||||
:param run_task: run callback in task (no wait results)
|
||||
"""
|
||||
|
||||
# Check number of arguments of the callback, cause only two arguments accepted.
|
||||
sig = signature(callback)
|
||||
if len(sig.parameters) != 2:
|
||||
raise RuntimeError('Errors handlers should accept only two arguments (current update and exception)')
|
||||
|
||||
filters_set = self.filters_factory.resolve(self.errors_handlers,
|
||||
*custom_filters,
|
||||
exception=exception,
|
||||
|
|
@ -827,6 +834,7 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
|
|||
:return:
|
||||
"""
|
||||
|
||||
|
||||
def decorator(callback):
|
||||
self.register_errors_handler(self._wrap_async_task(callback, run_task),
|
||||
*custom_filters, exception=exception, **kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue