More error handling for remote fetch
This commit is contained in:
parent
a1acbd16f3
commit
facdd2c080
@ -270,12 +270,15 @@ class Identity(StatorModel):
|
|||||||
(actor uri, canonical handle) or None, None if it does not resolve.
|
(actor uri, canonical handle) or None, None if it does not resolve.
|
||||||
"""
|
"""
|
||||||
domain = handle.split("@")[1]
|
domain = handle.split("@")[1]
|
||||||
async with httpx.AsyncClient() as client:
|
try:
|
||||||
response = await client.get(
|
async with httpx.AsyncClient() as client:
|
||||||
f"https://{domain}/.well-known/webfinger?resource=acct:{handle}",
|
response = await client.get(
|
||||||
headers={"Accept": "application/json"},
|
f"https://{domain}/.well-known/webfinger?resource=acct:{handle}",
|
||||||
follow_redirects=True,
|
headers={"Accept": "application/json"},
|
||||||
)
|
follow_redirects=True,
|
||||||
|
)
|
||||||
|
except (httpx.ReadTimeout, httpx.ReadError, httpx.RemoteProtocolError):
|
||||||
|
return None, None
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
return None, None
|
return None, None
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -303,7 +306,7 @@ class Identity(StatorModel):
|
|||||||
headers={"Accept": "application/json"},
|
headers={"Accept": "application/json"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
except (httpx.ReadTimeout, httpx.ReadError):
|
except (httpx.ReadTimeout, httpx.ReadError, httpx.RemoteProtocolError):
|
||||||
return False
|
return False
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
return False
|
return False
|
||||||
|
Reference in New Issue
Block a user