Errors handler

This commit is contained in:
Alex Root Junior 2020-04-12 22:13:25 +03:00
parent 569a9c807c
commit 9e673998f0
9 changed files with 150 additions and 3 deletions

View file

@ -80,6 +80,9 @@ class MyMiddleware(BaseMiddleware):
) -> Any:
return "poll_answer"
async def on_pre_process_error(self, exception: Exception, data: Dict[str, Any]) -> Any:
return "error"
async def on_process_update(self, update: Update, data: Dict[str, Any]) -> Any:
return "update"
@ -130,6 +133,9 @@ class MyMiddleware(BaseMiddleware):
async def on_process_poll_answer(self, poll_answer: PollAnswer, data: Dict[str, Any]) -> Any:
return "poll_answer"
async def on_process_error(self, exception: Exception, data: Dict[str, Any]) -> Any:
return "error"
async def on_post_process_update(
self, update: Update, data: Dict[str, Any], result: Any
) -> Any:
@ -188,6 +194,11 @@ class MyMiddleware(BaseMiddleware):
) -> Any:
return "poll_answer"
async def on_post_process_error(
self, exception: Exception, data: Dict[str, Any], result: Any
) -> Any:
return "error"
UPDATE = Update(update_id=42)
MESSAGE = Message(message_id=42, date=datetime.datetime.now(), chat=Chat(id=42, type="private"))
@ -206,7 +217,12 @@ class TestBaseMiddleware:
)
@pytest.mark.parametrize(
"event_name,event",
[["update", UPDATE], ["message", MESSAGE], ["poll_answer", POLL_ANSWER],],
[
["update", UPDATE],
["message", MESSAGE],
["poll_answer", POLL_ANSWER],
["error", Exception("KABOOM")],
],
)
async def test_trigger(
self,