Avoid crash if bad URL entered in 'add remote' #77

This commit is contained in:
freamon 2024-04-24 16:04:49 +01:00
parent 3cddfd86e8
commit 4dc0763881

View file

@ -38,9 +38,18 @@ def search_for_community(address: str):
return already_exists
# Look up the profile address of the community using WebFinger
# todo: try, except block around every get_request
webfinger_data = get_request(f"https://{server}/.well-known/webfinger",
params={'resource': f"acct:{address[1:]}"})
try:
webfinger_data = get_request(f"https://{server}/.well-known/webfinger",
params={'resource': f"acct:{address[1:]}"})
except requests.exceptions.ReadTimeout:
time.sleep(randint(3, 10))
try:
webfinger_data = get_request(f"https://{server}/.well-known/webfinger",
params={'resource': f"acct:{address[1:]}"})
except requests.exceptions.RequestException:
return None
except requests.exceptions.RequestException:
return None
if webfinger_data.status_code == 200:
webfinger_json = webfinger_data.json()
for links in webfinger_json['links']: