diff --git a/discord/client.py b/discord/client.py index 3b5b948b7..0990690ef 100644 --- a/discord/client.py +++ b/discord/client.py @@ -718,6 +718,9 @@ class Client: Raises ------- + GatewayNotFound + If the gateway to connect to Discord is not found. Usually if this + is thrown then there is a Discord API outage. ConnectionClosed The websocket connection has been terminated. """ diff --git a/discord/http.py b/discord/http.py index b6b0f625d..d34510591 100644 --- a/discord/http.py +++ b/discord/http.py @@ -53,7 +53,7 @@ import datetime import aiohttp from .enums import RelationshipAction, InviteType -from .errors import HTTPException, RateLimited, Forbidden, NotFound, LoginFailure, DiscordServerError, CaptchaRequired +from .errors import HTTPException, RateLimited, Forbidden, NotFound, LoginFailure, DiscordServerError, GatewayNotFound, CaptchaRequired from .file import File from .tracking import ContextProperties from . import utils @@ -4050,7 +4050,10 @@ class HTTPClient: # Misc async def get_gateway(self, *, encoding: str = 'json', zlib: bool = True) -> str: - data = await self.request(Route('GET', '/gateway')) + try: + data = await self.request(Route('GET', '/gateway')) + except HTTPException as exc: + raise GatewayNotFound() from exc if zlib: value = '{0}?encoding={1}&v={2}&compress=zlib-stream' else: diff --git a/docs/api.rst b/docs/api.rst index 70a0d4dea..59cf2bf8d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -7628,6 +7628,8 @@ The following exceptions are thrown by the library. .. autoexception:: InvalidData +.. autoexception:: GatewayNotFound + .. autoexception:: ConnectionClosed .. autoexception:: discord.opus.OpusError @@ -7645,6 +7647,7 @@ Exception Hierarchy - :exc:`InvalidData` - :exc:`LoginFailure` - :exc:`ConnectionClosed` + - :exc:`GatewayNotFound` - :exc:`HTTPException` - :exc:`Forbidden` - :exc:`NotFound`