Total Complexity | 2 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
2 | # Full MIT License can be found in `LICENSE` at the project root. |
||
3 | |||
4 | """ |
||
5 | non-subscription event sent when there is an error, |
||
6 | including command responses |
||
7 | """ |
||
8 | from __future__ import annotations |
||
9 | |||
10 | from typing import TYPE_CHECKING |
||
11 | |||
12 | from ..objects.events.error import DiscordError |
||
13 | from ..utils.types import Coro |
||
14 | |||
15 | if TYPE_CHECKING: |
||
16 | from typing import Tuple |
||
17 | from ..client import Client |
||
18 | from ..core.gateway import Gateway |
||
19 | from ..core.gateway import GatewayDispatch |
||
20 | |||
21 | |||
22 | def error_middleware( |
||
23 | self: Client, gateway: Gateway, payload: GatewayDispatch |
||
24 | ) -> Tuple[str, DiscordError]: |
||
25 | """|coro| |
||
26 | |||
27 | Middleware for the ``on_error`` event. |
||
28 | |||
29 | Parameters |
||
30 | ---------- |
||
31 | payload : :class:`~pincer.core.gateway.GatewayDispatch` |
||
32 | The data received from the ready event. |
||
33 | gateway : :class:`~pincer.core.gateway.Gateway` |
||
34 | The gateway for the current shard. |
||
35 | |||
36 | Returns |
||
37 | ------- |
||
38 | Tuple[:class:`str`, :class:`~pincer.objects.events.error.DiscordError`] |
||
39 | ``on_error`` and a ``DiscordError`` |
||
40 | """ |
||
41 | # noqa: E501 |
||
42 | |||
43 | return ("on_error", DiscordError.from_dict(payload.data)) |
||
44 | |||
45 | |||
46 | def export() -> Coro: |
||
47 | return error_middleware |
||
48 |