summaryrefslogtreecommitdiffstats
path: root/users
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-20 12:02:38 -0700
committerAndrew Godwin2022-11-20 12:02:38 -0700
commitfacdd2c08094ad378351375541fa8e65459fa8d1 (patch)
tree32be83cc0f95f1c58bb30cc38646d9d3a3cbc214 /users
parenta1acbd16f3fbf4fb9086837e4cf57911ede79cae (diff)
downloadtakahe-facdd2c08094ad378351375541fa8e65459fa8d1.tar.gz
takahe-facdd2c08094ad378351375541fa8e65459fa8d1.tar.bz2
takahe-facdd2c08094ad378351375541fa8e65459fa8d1.zip
More error handling for remote fetch
Diffstat (limited to 'users')
-rw-r--r--users/models/identity.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/users/models/identity.py b/users/models/identity.py
index 5056ce0..452bde7 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -270,12 +270,15 @@ class Identity(StatorModel):
(actor uri, canonical handle) or None, None if it does not resolve.
"""
domain = handle.split("@")[1]
- async with httpx.AsyncClient() as client:
- response = await client.get(
- f"https://{domain}/.well-known/webfinger?resource=acct:{handle}",
- headers={"Accept": "application/json"},
- follow_redirects=True,
- )
+ try:
+ async with httpx.AsyncClient() as client:
+ response = await client.get(
+ f"https://{domain}/.well-known/webfinger?resource=acct:{handle}",
+ headers={"Accept": "application/json"},
+ follow_redirects=True,
+ )
+ except (httpx.ReadTimeout, httpx.ReadError, httpx.RemoteProtocolError):
+ return None, None
if response.status_code >= 400:
return None, None
data = response.json()
@@ -303,7 +306,7 @@ class Identity(StatorModel):
headers={"Accept": "application/json"},
follow_redirects=True,
)
- except (httpx.ReadTimeout, httpx.ReadError):
+ except (httpx.ReadTimeout, httpx.ReadError, httpx.RemoteProtocolError):
return False
if response.status_code >= 400:
return False