File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ with the exception that all versions are currently `0.x.x` and may include break
2323
2424- Use response headers to determine whether to parse HTTP responses into JSON
2525- get() can also return ` list ` type as JSON can also be a list
26+ - Include response status code in HytaleAPIError
2627
2728### Fixed
2829
Original file line number Diff line number Diff line change 11class HytaleAPIError (Exception ):
22 """Base exception for Hytale API errors."""
33
4+ def __init__ (self , message : str , http_code : int | None ):
5+ super ().__init__ (message )
6+ self .http_code = http_code
7+
48
59class BlockedError (HytaleAPIError ):
610 """Exception for when access is blocked by Cloudflare."""
Original file line number Diff line number Diff line change 1414_session .headers .update (
1515 {
1616 "User-Agent" : DEFAULT_USER_AGENT ,
17- "Accept" : "application/json" ,
17+ "Accept" : "application/json" , # expect JSON but can handle other responses
1818 }
1919)
2020
@@ -48,14 +48,12 @@ def get(
4848 timeout = 3 ,
4949 )
5050 except requests .RequestException as exc :
51- raise HytaleAPIError (str (exc )) from exc
51+ raise HytaleAPIError (str (exc ), None ) from exc
5252
5353 if not response .ok :
5454 if "Attention Required! | Cloudflare" in response .text :
55- raise BlockedError ("This IP is blocked" )
56- raise HytaleAPIError (
57- f"Request failed [{ response .status_code } ]: { response .text } "
58- )
55+ raise BlockedError ("This IP is blocked" , response .status_code )
56+ raise HytaleAPIError (f"Request failed: { response .text } " , response .status_code )
5957
6058 content_type = response .headers .get ("Content-Type" , "" )
6159
You can’t perform that action at this time.
0 commit comments