Raise proper errors when it's our fault

This commit is contained in:
Andrew Godwin 2022-11-20 18:45:28 -07:00
parent 6a8fe5cb4b
commit 5de3a7ad67
1 changed files with 10 additions and 2 deletions

View File

@ -307,11 +307,15 @@ class Identity(StatorModel):
) )
except httpx.RequestError: except httpx.RequestError:
return None, None return None, None
if response.status_code == 404: if response.status_code in [404, 410]:
# We don't trust this as much as 410 Gone, but skip for now
return None, None return None, None
if response.status_code >= 500: if response.status_code >= 500:
return None, None return None, None
if response.status_code >= 400:
raise ValueError(
f"Client error fetching webfinger: {response.status_code}",
response.content,
)
data = response.json() data = response.json()
if data["subject"].startswith("acct:"): if data["subject"].startswith("acct:"):
data["subject"] = data["subject"][5:] data["subject"] = data["subject"][5:]
@ -347,6 +351,10 @@ class Identity(StatorModel):
return False return False
if response.status_code >= 500: if response.status_code >= 500:
return False return False
if response.status_code >= 400:
raise ValueError(
f"Client error fetching actor: {response.status_code}", response.content
)
document = canonicalise(response.json(), include_security=True) document = canonicalise(response.json(), include_security=True)
self.name = document.get("name") self.name = document.get("name")
self.profile_uri = document.get("url") self.profile_uri = document.get("url")