aboutsummaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-09-09 21:24:14 -0400
committerRapptz <[email protected]>2020-09-09 21:24:14 -0400
commit450e71f086b548cd294b7439d973befc9284193a (patch)
treed5c6e34f1b31a835e95f25f2bf4a891b235b7f19 /discord
parentGuard uses of the keep alive thread in case they're None (diff)
downloaddiscord.py-450e71f086b548cd294b7439d973befc9284193a.tar.xz
discord.py-450e71f086b548cd294b7439d973befc9284193a.zip
Add a more concrete exception for 500 status codes.
Fixes #5797
Diffstat (limited to 'discord')
-rw-r--r--discord/errors.py8
-rw-r--r--discord/http.py7
-rw-r--r--discord/webhook.py8
3 files changed, 20 insertions, 3 deletions
diff --git a/discord/errors.py b/discord/errors.py
index fec1f45d..bd78131a 100644
--- a/discord/errors.py
+++ b/discord/errors.py
@@ -122,6 +122,14 @@ class NotFound(HTTPException):
"""
pass
+class DiscordServerError(HTTPException):
+ """Exception that's thrown for when a 500 range status code occurs.
+
+ Subclass of :exc:`HTTPException`.
+
+ .. versionadded:: 1.5
+ """
+ pass
class InvalidData(ClientException):
"""Exception that's raised when the library encounters unknown
diff --git a/discord/http.py b/discord/http.py
index d91664c9..1ad11d9e 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -33,7 +33,7 @@ import weakref
import aiohttp
-from .errors import HTTPException, Forbidden, NotFound, LoginFailure, GatewayNotFound
+from .errors import HTTPException, Forbidden, NotFound, LoginFailure, DiscordServerError, GatewayNotFound
from .gateway import DiscordClientWebSocketResponse
from . import __version__, utils
@@ -252,6 +252,9 @@ class HTTPClient:
raise
# We've run out of retries, raise.
+ if r.status >= 500:
+ raise DiscordServerError(r, data)
+
raise HTTPException(r, data)
async def get_from_cdn(self, url):
@@ -659,7 +662,7 @@ class HTTPClient:
def get_template(self, code):
return self.request(Route('GET', '/guilds/templates/{code}', code=code))
-
+
def create_from_template(self, code, name, region, icon):
payload = {
'name': name,
diff --git a/discord/webhook.py b/discord/webhook.py
index 7824c55a..bd280230 100644
--- a/discord/webhook.py
+++ b/discord/webhook.py
@@ -34,7 +34,7 @@ from urllib.parse import quote as _uriquote
import aiohttp
from . import utils
-from .errors import InvalidArgument, HTTPException, Forbidden, NotFound
+from .errors import InvalidArgument, HTTPException, Forbidden, NotFound, DiscordServerError
from .enums import try_enum, WebhookType
from .user import BaseUser, User
from .asset import Asset
@@ -241,7 +241,10 @@ class AsyncWebhookAdapter(WebhookAdapter):
raise NotFound(r, response)
else:
raise HTTPException(r, response)
+
# no more retries
+ if r.status >= 500:
+ raise DiscordServerError(r, response)
raise HTTPException(r, response)
async def handle_execution_response(self, response, *, wait):
@@ -342,7 +345,10 @@ class RequestsWebhookAdapter(WebhookAdapter):
raise NotFound(r, response)
else:
raise HTTPException(r, response)
+
# no more retries
+ if r.status >= 500:
+ raise DiscordServerError(r, response)
raise HTTPException(r, response)
def handle_execution_response(self, response, *, wait):