Skip to content

Commit ca161ab

Browse files
committed
refactor: use response.status instead of retrieving it directly from the JSON response
1 parent f385123 commit ca161ab

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

topgg/errors.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,19 @@ class HTTPException(TopGGException):
7979
The response of the failed HTTP request.
8080
text (str)
8181
The text of the error. Could be an empty string.
82-
code (Optional[int])
82+
code (int)
8383
The response status code.
8484
"""
8585

8686
__slots__ = ("response", "text", "code")
8787

8888
def __init__(self, response: "ClientResponse", message: Union[dict, str]) -> None:
8989
self.response = response
90-
91-
if isinstance(message, dict):
92-
self.text = message.get("message", message.get("detail", ""))
93-
self.code = message.get("code", message.get("status"))
94-
else:
95-
self.text = message
96-
self.code = None
90+
self.code = response.status
91+
self.text = message.get("message", message.get("detail", "")) if isinstance(message, dict) else message
9792

9893
fmt = f"{self.response.reason} (status code: {self.response.status})"
94+
9995
if self.text:
10096
fmt = f"{fmt}: {self.text}"
10197

0 commit comments

Comments
 (0)