Skip to content

Commit

Permalink
Handle "error" key of response being a string in HTTPException
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Apr 21, 2022
1 parent 915854d commit 2da4452
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tweepy/errors.py
Expand Up @@ -45,16 +45,26 @@ def __init__(self, response):
super().__init__(f"{response.status_code} {response.reason}")
else:
errors = response_json.get("errors", [])

# Use := when support for Python 3.7 is dropped
if "error" in response_json:
errors.append(response_json["error"])

error_text = ""

for error in errors:
self.api_errors.append(error)

if isinstance(error, str):
self.api_messages.append(error)
error_text += '\n' + error
continue

if "code" in error:
self.api_codes.append(error["code"])
if "message" in error:
self.api_messages.append(error["message"])

if "code" in error and "message" in error:
error_text += f"\n{error['code']} - {error['message']}"
elif "message" in error:
Expand Down

0 comments on commit 2da4452

Please sign in to comment.