Make use of the check response.wait_for_status() and then return json response

This commit is contained in:
weibeu
2021-05-23 22:41:27 +05:30
parent 4d2e0fe2ea
commit 37f6c285ef

View File

@@ -1,7 +1,6 @@
import cachetools
import requests
import typing
import json
import abc
from . import configs
@@ -179,10 +178,12 @@ class DiscordOAuth2HttpClient(abc.ABC):
raise exceptions.RateLimited(response.json(), response.headers)
try:
return response.json()
except json.JSONDecodeError:
response.raise_for_status()
except requests.HTTPError:
return response.text
return response.json()
def bot_request(self, route: str, method="GET", **kwargs) -> typing.Union[dict, str]:
"""Make HTTP request to specified endpoint with bot token as authorization headers.