diff --git a/aiogram/utils/safe.py b/aiogram/utils/safe.py new file mode 100644 index 00000000..7ef5b8fc --- /dev/null +++ b/aiogram/utils/safe.py @@ -0,0 +1,16 @@ +import typing + + +async def safe(coro: typing.Coroutine) -> (bool, typing.Any): + """ + Safety execute coroutine + + Status - returns True if success otherwise False + + :param coro: + :return: status and result + """ + try: + return True, await coro + except Exception as e: + return False, e