From 739b394ccc63522f4aca72953bbc01826eaa3ee3 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 13 Mar 2022 12:31:21 -0700 Subject: [PATCH 1/2] Catch error when trying to update book --- bookwyrm/views/books/books.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py index ad7ee9436..3556a0dc1 100644 --- a/bookwyrm/views/books/books.py +++ b/bookwyrm/views/books/books.py @@ -12,7 +12,7 @@ from django.views.decorators.http import require_POST from bookwyrm import forms, models from bookwyrm.activitypub import ActivitypubResponse -from bookwyrm.connectors import connector_manager +from bookwyrm.connectors import connector_manager, ConnectorException from bookwyrm.connectors.abstract_connector import get_image from bookwyrm.settings import PAGE_LENGTH from bookwyrm.views.helpers import is_api_request @@ -191,6 +191,10 @@ def update_book_from_remote(request, book_id, connector_identifier): ) book = get_object_or_404(models.Book.objects.select_subclasses(), id=book_id) - connector.update_book_from_remote(book) + try: + connector.update_book_from_remote(book) + except ConnectorException: + # the remote source isn't available or doesn't know this book + pass return redirect("book", book.id) From c7efa2340505ae22f5f0d225eedb3716e2545eb9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 13 Mar 2022 12:38:29 -0700 Subject: [PATCH 2/2] Display error message for remote failure --- bookwyrm/templates/book/book.html | 9 +++++++++ bookwyrm/views/books/books.py | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 0e2fd5d39..fa098281e 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -12,6 +12,15 @@ {% endblock %} {% block content %} +{% if update_error %} +
+ + + {% trans "Unable to connect to remote source." %} + +
+{% endif %} + {% with user_authenticated=request.user.is_authenticated can_edit_book=perms.bookwyrm.edit_book %}
diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py index 3556a0dc1..a010c300f 100644 --- a/bookwyrm/views/books/books.py +++ b/bookwyrm/views/books/books.py @@ -22,7 +22,7 @@ from bookwyrm.views.helpers import is_api_request class Book(View): """a book! this is the stuff""" - def get(self, request, book_id, user_statuses=False): + def get(self, request, book_id, user_statuses=False, update_error=False): """info about a book""" if is_api_request(request): book = get_object_or_404( @@ -80,6 +80,7 @@ class Book(View): else None, "rating": reviews.aggregate(Avg("rating"))["rating__avg"], "lists": lists, + "update_error": update_error, } if request.user.is_authenticated: @@ -195,6 +196,6 @@ def update_book_from_remote(request, book_id, connector_identifier): connector.update_book_from_remote(book) except ConnectorException: # the remote source isn't available or doesn't know this book - pass + return Book().get(request, book_id, update_error=True) return redirect("book", book.id)