Fix server erroring when homeserver is unavailable
This commit is contained in:
parent
0af19ceb2f
commit
d55ceb2df2
1 changed files with 8 additions and 5 deletions
|
@ -271,10 +271,13 @@ def preview_url(
|
||||||
else:
|
else:
|
||||||
return MISSING_TOKEN
|
return MISSING_TOKEN
|
||||||
|
|
||||||
response = httpx.get(
|
try:
|
||||||
domain + "/_matrix/client/r0/account/whoami",
|
response = httpx.get(
|
||||||
headers={"Authorization": f"Bearer {access_token}"}
|
domain + "/_matrix/client/r0/account/whoami",
|
||||||
)
|
headers={"Authorization": f"Bearer {access_token}"}
|
||||||
|
)
|
||||||
|
except httpx.NetworkError as e:
|
||||||
|
raise HTTPException(504, detail=f"Failed to contact homeserver for authentication: {e}")
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return INVALID_TOKEN
|
return INVALID_TOKEN
|
||||||
|
|
||||||
|
@ -334,7 +337,7 @@ def preview_url(
|
||||||
e.response.status_code,
|
e.response.status_code,
|
||||||
f"Failed to fetch {e.response.url} - HTTP {e.response.status_code}: {e.response.text}"
|
f"Failed to fetch {e.response.url} - HTTP {e.response.status_code}: {e.response.text}"
|
||||||
)
|
)
|
||||||
except httpx.NetworkError as e:
|
except (httpx.NetworkError, ConnectionError) as e:
|
||||||
logging.debug(f"Failed to fetch {url}", exc_info=True)
|
logging.debug(f"Failed to fetch {url}", exc_info=True)
|
||||||
raise HTTPException(502, f"Failed to fetch {url} - {e}")
|
raise HTTPException(502, f"Failed to fetch {url} - {e}")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue