Closes by handling dodgy responses more consistently.
This will log a warning and then return the None value.
Added additional logging code for handling weird response types from REST API.
This fixes an issue where a 4xx with no body causes a key error also.
@@ -388,6 +388,10 @@ class LowLevelRestfulClient:
)
continue
else:
+ self.logger.debug(
+ "received unexpected response shape. Status: %s, Content-Type: %s, Body: %s",
+ status, content_type, raw_body
+ )
body = None
self.ratelimiter.update_rate_limits(compiled_route, bucket, remaining, limit, now_date, reset_date)
@@ -402,7 +406,9 @@ class LowLevelRestfulClient:
if status >= codes.HTTPStatusCode.BAD_REQUEST:
code = None
- if self.version == versions.HTTPAPIVersion.V6:
+ if body is None:
+ message = raw_body
+ elif self.version == versions.HTTPAPIVersion.V6:
message = ", ".join(f"{k} - {v}" for k, v in body.items())
else:
message = body.get("message")
