handle get_data exceptions better

Makes exception handling more precise, only raising status for 401s.

Also fixes a string pylint was complaining about.
This commit is contained in:
Hugh Rundle 2023-01-20 19:55:38 +11:00
parent f8c9df4aff
commit e8452011f7
2 changed files with 7 additions and 2 deletions

View file

@ -306,7 +306,8 @@ def resolve_remote_id(
def get_representative():
"""Get or create an actor representing the entire instance to sign requests to 'secure mastodon' servers"""
"""Get or create an actor representing the instance
to sign requests to 'secure mastodon' servers"""
username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}"
try:
user = models.User.objects.get(username=username)

View file

@ -244,7 +244,11 @@ def get_data(url, params=None, timeout=settings.QUERY_TIMEOUT):
raise ConnectorException(err)
if not resp.ok:
resp.raise_for_status()
if resp.status_code == 401:
# this is probably an AUTHORIZED_FETCH issue
resp.raise_for_status()
else:
raise ConnectorException()
try:
data = resp.json()
except ValueError as err: