forked from mirrors/bookwyrm
Error hanlding for user search
This commit is contained in:
parent
9efe1a3990
commit
8dba4ccf47
3 changed files with 11 additions and 5 deletions
|
@ -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):
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<div class="content-container">
|
||||
{% if not results %}
|
||||
<p>No results found for "{{ query }}"</p>
|
||||
{% endif %}
|
||||
{% for result in results %}
|
||||
<div>
|
||||
<h2>{{ result.username }}</h2>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue