diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index 9d894a26b..d12a0430a 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -43,7 +43,10 @@ def handle_account_search(query): except models.User.DoesNotExist: url = 'https://%s/.well-known/webfinger?resource=acct:%s' % \ (domain, query) - response = requests.get(url) + try: + response = requests.get(url) + except requests.exceptions.ConnectionError: + return None if not response.ok: response.raise_for_status() data = response.json() @@ -52,8 +55,8 @@ def handle_account_search(query): try: user = get_or_create_remote_user(link['href']) except KeyError: - return HttpResponseNotFound() - return user + return None + return [user] def handle_follow(user, to_follow): diff --git a/bookwyrm/templates/user_results.html b/bookwyrm/templates/user_results.html index 5c48d850c..94f8a82e0 100644 --- a/bookwyrm/templates/user_results.html +++ b/bookwyrm/templates/user_results.html @@ -1,6 +1,9 @@ {% extends 'layout.html' %} {% block content %}
+ {% if not results %} +

No results found for "{{ query }}"

+ {% endif %} {% for result in results %}

{{ result.username }}

diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 2bfc45a3c..0f34884a7 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -120,9 +120,9 @@ def search(request): query = request.GET.get('q') if re.match(r'\w+@\w+.\w+', query): # if something looks like a username, search with webfinger - results = [outgoing.handle_account_search(query)] + results = outgoing.handle_account_search(query) return TemplateResponse( - request, 'user_results.html', {'results': results} + request, 'user_results.html', {'results': results, 'query': query} ) # or just send the question over to book search