diff --git a/boticordpy/exceptions.py b/boticordpy/exceptions.py index 4b7bdc4..ed8fc0d 100644 --- a/boticordpy/exceptions.py +++ b/boticordpy/exceptions.py @@ -15,17 +15,10 @@ class HTTPException(BoticordException): The text of the error. Could be an empty string. """ - def __init__(self, response, message): + def __init__(self, response): self.response = response - if isinstance(message, dict): - self.text = message.get('message', '') - self.code = message.get('code', 0) - else: - self.text = message fmt = f"{self.response.reason} (Status code: {self.response.status})" - if self.text: - fmt = f"{fmt}: {self.text}" super().__init__(fmt) diff --git a/boticordpy/modules/bots.py b/boticordpy/modules/bots.py index 5595a0b..8630bad 100644 --- a/boticordpy/modules/bots.py +++ b/boticordpy/modules/bots.py @@ -46,8 +46,9 @@ class Bots: async with self.session.get(f'{Config.general_api}/bot/{botID}', headers=headers) as resp: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) + if status is not None: - raise status + raise status(resp) return data async def getBotComments(self, botID: int): @@ -65,7 +66,7 @@ class Bots: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data async def postStats(self, stats: dict): @@ -86,5 +87,5 @@ class Bots: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data diff --git a/boticordpy/modules/servers.py b/boticordpy/modules/servers.py index 63510ca..cc7900e 100644 --- a/boticordpy/modules/servers.py +++ b/boticordpy/modules/servers.py @@ -48,7 +48,7 @@ class Servers: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data async def getServerComments(self, serverID: int): @@ -66,7 +66,7 @@ class Servers: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data async def postServerStats(self, message: discord.Message, custom_stats: dict = None): @@ -107,5 +107,5 @@ class Servers: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data diff --git a/boticordpy/modules/users.py b/boticordpy/modules/users.py index eac76db..3ca9bc4 100644 --- a/boticordpy/modules/users.py +++ b/boticordpy/modules/users.py @@ -41,7 +41,7 @@ class Users: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data async def getUserComments(self, userID: int): @@ -59,7 +59,7 @@ class Users: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data async def getUserBots(self, userID: int): @@ -77,5 +77,5 @@ class Users: data = await _json_or_text(resp) status = Config.http_exceptions.get(resp.status) if status is not None: - raise status + raise status(resp) return data